python_公共方法
程序员文章站
2022-04-29 20:53:44
1.计算长度 2.索引取值 3.切片 ......
1.计算长度
value = "wangdianchao" # 计算字符个数(长度) number = len(value) print(number)
2.索引取值
value = "wangdianchao" # 获取value“0”位置的字符 number = value[0] print(number)
value = "wangdianchao"
# 获取value右侧第一个的字符
number = value[-1]
print(number)
3.切片
value = "wangdianchao" # 2<=索引位置<3 number = value[2:4] print(number)
value = "wangdianchao"
# 从2取到最后
number = value[2:]
print(number)
value = "wangdianchao"
# 从0取到-2之前
number = value[:-2]
print(number)
上一篇: 养颜补肾粥有哪些
下一篇: memcached源码分析-slab