例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")
结果如下图所示
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")
结果如下图所示