Friday, March 11, 2011

Mar. 11

>>> import string
>>> string.find("bob", "b", 1, 2)
-1
With this input off of the string module, I was confused as to how did the program get an output of -1. I'm just confused with that part of the program
>>> '2**10 = 1024 and 4 * 5 = 20.000000'
'2**10 = 1024 and 4 * 5 = 20.000000'
>>> "His name is %s." % "Arthur"
'His name is Arthur.'
>>> name = "Alice"
>>> age = 10
>>> "I am %s and I am %d years old." % (name, age)
'I am Alice and I am 10 years old.'
>>> n1 = 4
>>> n2 = 5
>>> "2**10 = %d and %d * %d =  %f" % (2**10, n1, n2, n1 * n2)
'2**10 = 1024 and 4 * 5 =  20.000000'
With the % input, you can have it stand for different things such as from the program the first %s = name and then the second %d = age..

No comments:

Post a Comment