Difference between using ' and "?

mergesort picture mergesort · Feb 23, 2011 · Viewed 90.9k times · Source

Possible Duplicates:
Difference between the use of double quote and quotes in python
Single quotes vs. double quotes in Python

So I am now learning python, and was creating a function. What is the difference between using ' and ". I will create a sample function below to exemplify my question.

def question(variable):
    print variable

now what is the difference between calling

question("hello")

and

question('hello')

they both print hello, but why can I use both? Is it just because python is flexible? I was confused because ' is usually used for chars where as " is for strings for java right?

Answer

user225312 picture user225312 · Feb 23, 2011

Both are equal and what you use is entirely your preference.

As far as the char vs string thing is concerned, refer to the Zen of Python, (PEP 20 or import this)

Special cases aren't special enough to break the rules.

A string of length 1 is not special enough to have a dedicated char type.

Note that you can do:

>>> print 'Double" quote inside single'
Double" quote inside single
>>> print "Single' quote inside double"
Single' quote inside double