首页 > 文章列表 > python字符串如何取值

python字符串如何取值

python字符串
102 2022-08-07

1、说明

字符串都有序列存储。第一个字节的索引是0,第二个索引是1,第三个是2,一次排序。在字符串中空格也占字节。

2、实例

str1 = 'Hello World'
print(str1[0])
print(str1[0:5])
print(str1[6:11])

输出结果:

H
Hello
World

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。