python 入坑之路一 《字符串运算》
2020-04-24 本文已影响0人
Coderliszt
# # # # # # # # # # # # # # # # # # # # #
# # 微信公众号 # # # #
# # # <编程生涯> # # # #
# # # # # # # # # # # # # # # # # # # # #
# 截取字符串 第一位
print("hello world"[0])
# 截取最后一位字符串
print('hello world'[-1])
# 从多少下标截取到多少下标
print('hello world'[0:3])
# 还可以这样截取
print('hello world'[0:-1])
# 作业标题 用两种方式截取world
# 第一种
print('hello world'[6:11])
# 第二种(输入第一个下标,第二个什么都不输入就会自动截取到最后)
print('hello world'[6:])