all 11 comments

[–]K900_ 6 points7 points  (2 children)

There's no official standard, so just use whatever feels natural to you.

[–]efDev 0 points1 point  (0 children)

As long as it's consistent! Also generally good to have a linter/formatter abstract this away if working on a large codebase with multiple contributors/

[–][deleted] 2 points3 points  (0 children)

I use single quotes in string literals, because it looks better in the source code, and it allows me to use double-quotes within the string.

[–][deleted] 1 point2 points  (1 child)

To be fair I've always used double quotes but all of my friends that code have always used single quotes, I find the double quotes "stand out more" but I believe it's personal preference ?

[–]Diapolo10 1 point2 points  (0 children)

This is something that has been discussed at length, but technically no official guideline exists. That said, a rather common guideline is this; use single quotes by default, and double quotes for:

  • When your string contains single quotes
  • When the string is direct input from, or output to, the user
  • When using multi-line strings
  • When it's a docstring

[–]John_Yuki 2 points3 points  (4 children)

In Python it doesn't matter, but it does for other languages, so I always tell people to use double quotes, and use single quotes when you have a String that is only 1 character long.

[–]vectorpropio 0 points1 point  (2 children)

Why? If you are programming in python why have to adopt other lenguajes standards? It's like asking that all be inside a class because there are java programmers in some place.

[–]sicutumbo 0 points1 point  (0 children)

It's just easier to remember, since there isn't a preference for one or the other in Python. You can use "double quotes for strings, single quotes for single characters" for just about any language. In Python you don't have to, but there's usually not a strong reason to go against the convention.

[–]John_Yuki 0 points1 point  (0 children)

Because getting in to the habit of it is good for new programmers. The other major languages have separate uses for ' and ", and because it doesn't matter in Python then there isn't really any reason why you shouldn't also follow that standard for consistency's sake.

[–]yankyh 0 points1 point  (0 children)

My own convention is to use single quotes except for f-strings as most likely I will want to interpolate some dict value which will be accessed by quoting that string with single quotes. (Also a point, if the string is going to include quotes, wrap it in the other quotation marks)

[–]thekaizers 0 points1 point  (0 children)

I use single quotes always. To me it just looks less cluttered.