例2.1字符串操作示例

python中字符串用单引号或者双引号括起来

访问字符串时,采用方式:

变量[头下标:尾下标]

str1= "Hello word!"
print(str1)
print(str1[0:-1])
print(str1[-1])
print(str1[2:5])
print(str1[2:])
print(str1 * 2)
print("学号:3008")

结果如下图所示

posted @ 2024-10-15 16:30  方~~  阅读(23)  评论(0)    收藏  举报