Python Forum
Is it possible to have an apostrophe inside { } in an f-string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to have an apostrophe inside { } in an f-string?
#1
from random import choice as rc

string = f"never say you {rc(['can', 'can\'t'])} do something"

print(string)
Output:
File "C:/Users/Exsul/.PyCharmCE2019.2/config/scratches/scratch.py", line 3 string = f"never say you {rc(['can', 'can\'t'])}" ^ SyntaxError: f-string expression part cannot include a backslash Process finished with exit code 1
How can I put an apostrophe inside the curly brackets, since I can't escape an end quotation mark with \?
Reply


Messages In This Thread
Is it possible to have an apostrophe inside { } in an f-string? - by Exsul - Sep-04-2019, 12:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  CSV not printing apostrophe correctly bazcurtis 8 2,499 Aug-22-2022, 04:28 PM
Last Post: bazcurtis
  converting string object inside a list into an intiger bwdu 4 2,633 Mar-31-2020, 10:36 AM
Last Post: buran
  Python Parameter inside Json file treated as String dhiliptcs 0 1,851 Dec-10-2019, 07:28 PM
Last Post: dhiliptcs
  If statement containing apostrophe AshBax 11 5,248 Jul-09-2019, 01:34 PM
Last Post: AshBax
  How do I put a variable inside a String in Python? evilcode1 8 6,118 Sep-25-2018, 04:53 PM
Last Post: evilcode1
  replace string inside double quotes jmpatx 10 16,628 Apr-26-2017, 05:27 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020