码迷,mamicode.com
首页 > 编程语言 > 详细

python基础(七)--字符串的索引与切片

时间:2020-03-27 00:41:17      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:nbsp   字符   --   int   bsp   abc   pytho   索引   基础   

‘‘‘
s = ‘ABCDLSESRF‘
#索引
# s1 = s[0]
# print(s1)
# s2 = s[2]
# print(s2)
# s3 = s[-1]
# print(s3)
# s4 = s[-2]
# print(s4)
# #ABCD   切片 :顾头不顾尾
# s5 = s[0:4]
# print(s5)
# s6 = s[0:-1]
# print(s6)
# s7 = s[:]
# s8 = s[0:]
# print(s7,s8)
# s9 = s[0:0]
s = ‘ABCDLSESRF‘  # s[首:尾:步长]
# s10 = s[0:5:2]
# print(s10)
s11 = s[4:0:-1]
print(s11)
s12 = s[3::-1]
print(s12)
s13 = s[3::-2]
print(s13)
s = ‘ABCDLSESRF‘
s14 = s[-1::-1]
print(s14)
s15 = s[::-1]
print(s15)
‘‘‘

python基础(七)--字符串的索引与切片

标签:nbsp   字符   --   int   bsp   abc   pytho   索引   基础   

原文地址:https://www.cnblogs.com/qingmuzi/p/12578611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!