Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between using ' and "? [duplicate]

Tags:

python

quotes

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?

like image 725
mergesort Avatar asked Feb 23 '11 05:02

mergesort


People also ask

What do you mean by duplicate?

1a : either of two things exactly alike and usually produced at the same time or by the same process. b : an additional copy of something (such as a book or stamp) already in a collection. 2 : one that resembles or corresponds to another : counterpart. 3 : two identical copies —used in the phrase in duplicate.

What is difference between replicate and duplicate?

The word duplicate is derived from the Latin word duplicare, which means to double. Replicate means to reproduce something, to construct a copy of something, to make a facsimile. The word replicate may be interchangeable with the word duplicate except in a few instances.

What is the purpose of using duplicate?

If you duplicate something that has already been done, you repeat or copy it. His task will be to duplicate his success overseas here at home. Duplicate is used to describe things that have been made as an exact copy of other things, usually in order to serve the same purpose. He let himself in with a duplicate key.

What is the difference between duplicate and reference?

In simple terms, Duplicate will duplicate the code of the query while Query Reference will only refer the result of the query. Duplicate is generally used when you would like to create a similar query and you do not want to type the same code. You can make changes to this query.


2 Answers

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 
like image 154
user225312 Avatar answered Oct 01 '22 12:10

user225312


" is useful when you have ' into the string and vice versa

like image 26
luc Avatar answered Oct 01 '22 11:10

luc