1

While I am developing the Python code, I found I used to use single quotation marks all the time, but some experienced programmers used double quotation marks more often. I couldn't find the difference between them, could anyone help to give me some examples if there is a difference? Or is it just a personal preference? For example:

class TextBox(UIControl):
    def draw(self):
    print('TextBox')

class TextBox2(UIControl):
    def draw(self):
        print("TextBox")

class TextBox and TextBox2 seems like have no difference while running. Thanks for your help!

Joey
  • 125
  • 8
  • [Nothing but style](https://docs.python.org/3/tutorial/introduction.html#strings) – ChrisGPT was on strike Aug 31 '20 at 00:41
  • 1
    [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied and offer poor usability. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike Aug 31 '20 at 00:42
  • Also worth mentioning that if you have a single quote in string, like can't, using a double quote prevents you from having to escape the single quote with a back slash. – John Greenfield Aug 31 '20 at 00:42

2 Answers2

1

There is no difference between them, except for the looks. For example if you did:

print("Hello world")

It is the same as:

print('Hello world')

But I like to do the first one.

1

The uses of quotation marks and double quotation marks are the same, but you can use them in different cases; I'll give some examples as follows;

# Use of quotation mark ''
print('This is a "python code"')

# Use of double quotation mark ""
print("This is a 'python code'")

# More specific case (triple quotation mark)
print('''"This is a 'python code'"''')

If quotation mark is in a text to print, you should use double quotation mark. If double quotation mark is in a text to print, you should use quotation mark. If both of them is in a text to print, you should use triple quotation mark.

I'd be very happy if you let me know your opinion.

Ahmed Mamdouh
  • 696
  • 5
  • 12