书写格式
来源:互联网 发布:淘宝中国一号白银店铺 编辑:程序博客网 时间:2024/04/27 21:41
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” 都返回一样的结果
x = "There are %d types of people." % 10
binary= "binary"
do_not= "don't"
y= "Those who know%s and those who%s."%(binary,do_not)
printx
printy
print"I said: %r."%x
print"I also said: '%s'."%y
hilarious= False
joke_evaluation= "Isn't that joke so funny?! %r"
printjoke_evaluation % hilarious
w= "This is the left side of..."
e= "a string with a right side."
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 ..'.
- 书写格式
- 代码书写的格式
- 源程序格式书写规范
- 注释书写格式
- 英文地址书写格式
- MakeFile文件书写格式
- 英文地址书写格式
- Java Doc 书写格式
- Jboss首页书写格式
- SQL语句书写格式
- 英文地址书写格式
- 硕士论文书写格式
- fortran中的书写格式
- 论文书写---格式控制
- 英文邮件书写格式
- 参考文献书写格式
- Java 一些书写格式
- 黑马书写格式
- 黑马程序员--java面向对象
- 使用tcmalloc的一些问题
- 优秀平面设计师是怎样炼成的
- swf 格式Flash 动画播放器在Android上的实现
- JSR-303规范,Bean Validation
- 书写格式
- jQuery局部刷新的实现
- Expect安装方法
- MVVM 的使用
- 愚蠢的矿工--树形动态规划
- ASP.net 类库中获得当前路径的方法(非页面中)
- hdu 1285——确定比赛名次(拓扑排序)
- WinForm中,Button按钮有PerformClick()方法,可以模拟用户单击鼠标. 即button.PerformClick()生成按钮的事件。
- 最小公倍数