python_公共方法
程序员文章站
2022-07-01 16:15:06
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)
上一篇: 猛烈竞争下 互联网企业如何才能生存?