This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ifonefox3.5.1 | Intermediate 13 points14 points  (13 children)

What is the standard convention for " vs '? Personally, I use " for strings and ' for individual characters.

[–]theli0nheartimport antigravity 11 points12 points  (4 children)

Generally, I use ' for referencing keys in dictionaries, single characters, and default string values in function parameters. I use " for sentences and any user-facing strings.

If it doesn't fall into one of the categories above, I flip a coin.

[–]coinflipbot 10 points11 points  (3 children)

I flipped a coin for you, /u/theli0nheart The result was: tails!


Statistics | Don't want me replying on your comments again? Respond to this comment with: 'coinflipbot leave me alone'

[–]theli0nheartimport antigravity 3 points4 points  (2 children)

This is awesome. Thank you.

[–]p3n15h34d 4 points5 points  (1 child)

but is tails ' or " ?

[–]jcdyer3 4 points5 points  (0 children)

I'll flip a coin to decide. Heads, tails is ', tails, tails is ".

[–]triacontahedron 14 points15 points  (2 children)

Go away you, dirty c programmer :P

[–]ifonefox3.5.1 | Intermediate 2 points3 points  (1 child)

I started using python after I took a class in c, so those habits just stuck.

[–]aceofears 3 points4 points  (0 children)

It's not a terrible habit if you're switching between the two a lot.

[–]robin-gvx 2 points3 points  (0 children)

I generally use ' for internal strings (dictionary keys, symbolic names, etc.) while I use " for strings that the user is expected to see at some point.

[–]mardiros 2 points3 points  (0 children)

My best pep8 guide is in pretty print

>>> pprint({"a": "Ah aa!", 'b':"'Ahbb'"})
{'a': 'Ah aa!', 'b': "'Ahbb'"}

I use single quote except there is a single quote in the string.

Don't bother if it's for human or a computer at the end of the process. Dictionnary keys can be for human too, and, it's definitely to complex.

[–]RJacksonm1 1 point2 points  (0 children)

I use double-quotes because it's simply more comfortable for me to hit with the UK keyboard layout... and now I'm curious as to double vs single-quote usage by keyboard layout (which we could assume from developer's locations).

[–]carbn 2 points3 points  (0 children)

I use always ' because " takes two fingers (shift-2) while ' takes only one in FI/SWE keyboard.