a = "Simple string"
b = 'or with single quotes'# this is a comment# 1 this
# 2 is
# 3 a
# 4 multiline
# 5 commentc = "Mario's pizza"
d = 'she says: "Hi"' e = """Within triple quotes you'll do "anything". """def myFunc():
"""Here we can explain what myFunc does"""
passusage:
myFunc.func_doc
# or
help(myFunc)The help() tool will open a special help screen, where you can read all about the topic. As example, try the following with the previously installed noise library.
import noise
help(noise)Note: to exit the help() screen, press the Q key.
"Hello " + "World"becomes
'Hello World'"Hello %s, how are you %s?" % ("Dirk", "today")outputs
"Hello Dirk, how are you today?"You can use these placeholders:
%sfor String%dfor Integer digits%ffor Float
Example:
"To buy %d %s will cost you %f" % (3, "beers", 7.5)outputs:
'To buy 3 beers will cost you 7.500000'Float precision
"%.2f" % (7.5)gives:
'7.50'len("abacadabra hocus pocus")returns
22- convert a number to a string
- convert a string into a number (if applicable)
- make lowercase / UPPERCASE / Capitalize Each Word
- count the number of occurances of a substring (or single character)
- split string into (an array) of words
- strip off characters from the beginning or end (e.g. whitespace)
- ...