Quick python question - how to add apostrophe to string?
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!
myString = 'That\'s my cat.'
[link]http://www.python.org/doc/current/ref/strings.html[/link]
[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)?
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)?
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.
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.
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
b) isinstance(somevar, int) ## check if var is an int
As the poster above noted, isdigit is defined for strings
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement