Python(1):HelloWorld

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

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


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


2.串联字符串,可以用+,也可以不用,直接写出来就行了


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

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

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


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





























转载于:https://www.cnblogs.com/fablegame/p/6430182.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值