irisWhq

python 字符串相关知识

1. float转String
a = 1.2553435435435 # f前面的数字表示,保留的小数位数 bb = "%.0f" % a print(bb)

 2. Python 字符串中,个单词反转,保留空格

1 import re
2 str_a = "I love this Game"
3 str_split = re.split('(\s+)', str_a)
4 str_split.reverse()
5 print("".join(str_split)) #将数组转成字符串

输入结果:  Game this love I

3. 关于切片的语法:

[起始:结束:步长], 也可以简化为[起始:结束]

list_arr[0:3], 索引从0开始取,直到索引3结束,且不包括索引3.即: 0,1,2

posted on 2019-09-23 15:23  irisWhq  阅读(1641)  评论(0编辑  收藏  举报

导航