Difference between " and '

Robert Kern rkern at ucsd.edu
Thu Jul 21 21:12:04 EDT 2005


jepler at unpythonic.net wrote:
> The only difference is when you want to include " or ' inside the string.  If
> you want to include the "like" quote, then escape it ("\"", '\'').  If you
> include the "unlike" quote, no escape is needed ("'" or '"').
> 
> I think that people new to programming will use '' if it is unshifted on their
> keyboards.  People from a "C" background may use "" for strings (since in that
> language, '' is for a single character only).

I find that I switch between the two pretty freely. One habit that seems 
to crop up, though, is that I will use '' for internal strings and "" 
for strings that will eventually get seen by the user.

Don't ask me why.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list