you will get Hey you there·····························
非常重要
这里的print函数 “”当中出现的%d %s等正如c当中的一样,后面紧跟自己要添加的数据
不同之处
print "If I add %d,%d, and%d I get%d."%(my_age,my_height,my_weight,my_age+my_height+my_weight)
这里并不是分开写,而是用()来集中起来
变换数据类型时,要注意
eg
int(raw_input(“enter your name:”))
也就是注意input 和 raw_input之间的区别
input 假定用户输入的都是合法的Python表达式
raw_input 把所有的输入当做原始数据,然后将其放入字符串中
比如
name=input("What's your name?")
print "Hello,"+name+"!"
只有在输入为"canlan"时才能行
name=raw_input("What's your name?")
print "Hello,"+name+"!"
只有在输入为 canlan 时就可以了
Strings may contain the format characters you have discovered so far. You simply put the formatted variables in the string, and then a% (percent) character, followed by the variable. Theonly catch is that if you want multiple formats in your string to print multiple variables, you need to put them inside( ) (parenthesis) separated by, (commas).
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))
print strHello
#输出果:the length of (Hello World) is 11
这里不管使用‘hello world’还是 “hello world” 都返回一样的结果
print w +e##注意这里的加号···表示两个字符串的相连···
这里print "I also said: %s" %y 时输出 I also said:Those who ...
这里print "I also said:' %s'" %y 时输出 I also said:'Those who ..'.