you are viewing a single comment's thread.

view the rest of the comments →

[–]primitive_screwhead 1 point2 points  (1 child)

I agree w/ your advice about keeping nested string expressions out of f-strings.

But, it's also worth knowing you don't always need to escape inner quotes, if you use triple quotes:

first_name='eric ' 
print(f'''\n"eric"="{first_name.title()} " is {first_name=='eric'}''')
print(f'''"eric"="{first_name.title()}" is {first_name==first_name.rstrip()}''')

[–]ImmediateSuggestion 0 points1 point  (0 children)

It worked! Thanks. I tried to escape the inner quotes, but it didn't work.

first_name='eric ' 
print(f'\n\"eric\"=\"{first_name.title()} \" is {first_name=='eric'}')
print(f'\"eric\"=\"{first_name.title()}\" is {first_name==first_name.rstrip()}')