Python(1):HelloWorld

python安装很简单,没有什么要注意的地方。python

惟一要考虑的是,2.x版本和3.x版本。听说是改动太大,最好只能独立维护。不过初学者嘛,最好仍是用新版本的了。shell


1.单引号,双引号,三个双引号是等价的。


2.串联字符串,能够用+,也能够不用,直接写出来就好了函数


3.字符串格式说明符%scode

"John Q. %s" % ("Public")
"John %s%s" % ("Every","Man")

字符串依次被替换到%s的位置blog


4.能够指定插入字符的长度,若是是数量比字符串短则不处理,若是比插入的字符串长则以空格补充。正数补在左边,负数补在右边。
>>> "%5s%s" % ("abc", "def")
'  abcdef' --空格补在左边
>>> "%-4s%s" % ("abc", "def")
'abc def' --空格补在右边

5.在字符串里面的转义字符,直接在shell中输入是没有效果的。可是print函数能够。
>>> "Rock a by baby, \n\ton the tree top, \t\when the windblows\n\t\t\t the cradle will drop"
'Rock a by baby, \n\ton the tree top, \t\\when the windblows\n\t\t\t the cradle will drop'
>>> print("Rock a by baby, \n\ton the tree top, \t\when the windblows\n\t\t\t the cradle will drop")
Rock a by baby, 
	on the tree top, 	\when the windblows
			 the cradle will drop
相关文章
相关标签/搜索