Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any differences in " " and ' ' in Python? [duplicate]

I am new to programming and coding, and I choose Python to be my first. When I declare a variable, I notice that the variable = "x" and variable ='x' are the same. So can anyone told me the differences of "x" and 'x'

like image 868
zinhdragon Avatar asked Jun 18 '26 21:06

zinhdragon


1 Answers

According to PEP 8(Python Coding standard)

In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability. For triple-quoted strings, always use double quote characters to be consistent with the docstring convention in PEP 257.

e.g ‘single-quote’ is the same as “single-quote” You will need a double quote when you need apostrophe in the middle of the string e.g “I’m a good boy”

like image 60
John Adeniran Avatar answered Jun 21 '26 11:06

John Adeniran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!