Quick python question - how to add apostrophe to string?

Started by
5 comments, last by thedustbustr 19 years ago
As a string of text in python can be defined by surrounding it with apostrophes, how does one actually add an apostrophe to a string? So if I wanted to do something like this: myString = 'That's my cat.' How would it be done? I know you can do stuff like that for C quotes, so I would think there'd be a way to handle it in python (because python is totally cool). Thanks in advance!
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
myString = 'That\'s my cat.'

[link]http://www.python.org/doc/current/ref/strings.html[/link]
Thanks, AP.

Also, is there a built in isdigit function that will look at a character and return true if that character is a digit (0-9)?
Without order nothing can exist - without chaos nothing can evolve.
string = 'here%cs the best way to insert an apostrophe in a string in python." % 39

or maybe even

string = ('%c' % 39).join(('here', 's the best way to insert an apostrophe in a string in python.'))



just kidding.
http://en.wikibooks.org/wiki/Programming:Python_Strings

Yes, isdigit is listed as a built in string function.
a) myString = "This is Mike's cat" (note that double quotes are on the outside)

b) isinstance(somevar, int) ## check if var is an int

As the poster above noted, isdigit is defined for strings
>>> '1'.isdigit()True

This topic is closed to new replies.

Advertisement