打印,变量,注释
打印:注意全角半角混乱拼写会出现问题
注释:添加注释时候会出现编译格式不正确的情况
多数情况下提示no encoding declared,解决方法:首排加上#coding=utf-8 或者 # -*- coding:utf-8 -*-
变量:
y = "Those who know %s and those who %s." % (binary, do_not)
2个变量分别对应2个
print formatter % (1, 2, 3, 4)
也可以一个对应多个变量值,前提是加上 变量的解释如
formatter =( "%r %r %r %r" )
对应一个
days = "Mon Tue Wed Thu Fri Sat Sun"
print "Here are the days: ", days
其他:1.
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print("Here are the months:"), months # 打印时候可以分段落显示
2.
print '''
There's something going on here.
with the three double-quotes.
we'll be able to type as much as we like.
Even 4 lines if we want,or 5,or 6.
''' # 长串分段落的需要打印时候可以用三个引号符号,可以加括号也可以不加
3.
print("I 'said' do not touch this")#如果中间有字符串需要显示引号,前后有双引号的情况下,具体字符串选择单引号
4.
#让你的脚本多打印一行空白 print("\n")
5.让你代码只打印一行,在每行打印最后加上逗号
网友评论