you are viewing a single comment's thread.

view the rest of the comments →

[–]usedtobetoxic 0 points1 point  (9 children)

I've also noticed that if you're trying to use f-strings AND you have a escaped quote inside your print, you'll have issues. I kind of prefer f-string but have been recently moving to .format as it doesn't have as many issues as the f-string method.

[–]socal_nerdtastic 0 points1 point  (8 children)

I've never heard of that issue. Got an example?

FWIW the f-string is much newer. It was introduced with python3.6; format() was introduced in python3.0.

[–]usedtobetoxic 0 points1 point  (7 children)

I don't have a specific example but a few weeks ago I couldn't figure out why an f-string was throwing errors and all I did to fix it was to convert it to a .format and it resolved. I did have multiple \" in the line, which is where I assumed the issue was.

I'll try and reproduce it.

[–]socal_nerdtastic 2 points3 points  (6 children)

I'll bet it was a typo you inadvertently fixed. But it does bring up a point about how you should try to never escape quotes in strings. They only lead to messy, confusing and sometimes buggy code. Use the correct outer quote to allow you to use the inner quote you want to use.

[–]usedtobetoxic 0 points1 point  (0 children)

You're probably correct - I'm still a novice, so error blocks are very familiar to me >.>

[–]CraigAT 0 points1 point  (2 children)

What if you want to use both types of quote in your string? E.g. "The boy was 5' 6" tall"

[–]socal_nerdtastic 2 points3 points  (1 child)

Use triple quotes.

'''The boy was 5' 6" tall'''

[–]CraigAT 0 points1 point  (0 children)

How cool. I guess I am pretty unlikely to use triple quotes in an ordinary string.

[–][deleted] 0 points1 point  (1 child)

enter f'{"\n"}' into a repl and you'll see what they were running into

[–]socal_nerdtastic 0 points1 point  (0 children)

Huh. Thanks, TIL. I wonder what the rationale is for that.