首页 > Python > python_公共方法

python_公共方法

2019-08-12

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)

?

yabovip31.net亚博体育下载链接yabo亚搏 原文链接:https://www.cnblogs.com/wangdianchao/p/11341412.html

文章标签: