python注意事项2

工具pycharm

1.字符串的方法

hello_str = "hello world"

以什么开始      hello_str.startwith("h")

以什么结束      hello_str.endwith()


去除空白字符:

string.lstrip()------去除左边的空白字符

string.rstrip()-----去除右边的空白字符

string.strip()------去除空白字符


扫描二维码关注公众号,回复: 1028153 查看本文章

字符串拆分和连接:


string.split(str = " ",num)   -----返回列表

string.join(seq)-------返回字符串



字符串的切片 slice----str [开始索引,结束索引,间隔]:

>= 开始索引 < 结束索引  结束不填表示截取到最后

倒序从-1开始



元组和列表可以切片、*,但是字典不能切片、*



for循环要注意的:


搭建架构时,可以用pass

用户输入,字典储存,加入列表


end = " " ------以空格分割,不换行

end = "\t\t" --------分开更多,不换行

打印字典:


return 关键字 return执行了,后面的for循环不再执行







猜你喜欢

转载自blog.csdn.net/qq_40053669/article/details/80373019