首页 > IT职业 > IT图书 > python字符串如何取值

1、说明
字符串都有序列存储。第一个字节的索引是0,第二个索引是1,第三个是2,一次排序。在字符串中空格也占字节。
2、实例
str1 = 'Hello World' print(str1[0]) print(str1[0:5]) print(str1[6:11])
输出结果:
H Hello World
以上就是python字符串取值的方法,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1976/viewspace-2830199/ ,如需转载,请注明出处,否则将追究法律责任。