''
'字符串:是以单引号或双引号括起来的任意文本,
‘abc’
"def"
字符串不可变
''
'
#创建字符串
str1 =
"sunck is a good man!"
str2 =
"sunck is a nice man!"
#字符串运算
#字符串连接,字符串不可变
str3 =
"sunck"
str4 =
"is a man"
str5 = str3 + str4
print
(str5)
#输出重复字符串
str6 =
"hello"
str7 = str6 * 3
print
(str7)
#访问字符串中的某一个字符
#通过索引下标查找字符,从0开始 字符串名[下标]
str8 =
"sunck is a nice man!"
print
(str8[1])
#截取字符串,包含前面的6,不包含15[6,15),
str9 =
"sunck is a nice man!"
str10 = str9[6:15]
str11 = str9[:6]#从头截取
str12 = str9[16:]#从给定下标处截取到最后
print
(str10)
#判断有没有需要的字符
str13 =
"sunck is a nice man!"
print
(
"good"
in str13)#false
print
(
"good"
not in str13)#true