一、字符串s
s = "hello"
s = 'hello'
s = """hello""" #支持多行 #支持注释?
s = '''he
llo''' #支持多行 #支持注释
#为什么要单引号和双引号的区别
s = "hello"word""#word后面识别不出,报错
<h2>s = 'hello"word"'#方案一</h2>s = '''hello"word"'''#方案二,从左至右匹配
s = """hello"word""""#报错,见上有无解决方法,有
s = """hello"word/""""#同C语言/表示转义,下一个不处理?跳过!
二、转义字符
三、字符串的运算
s0 = "aa"
s1 = "bb"
print(s0,s1)
s2 = s0 + s1
print(s2,len(s2)) #输出aabb 4
s3 = s0 * 4
print(s3,len(s3)) #只能用Int类型,输出aaaaaaaa
if s0 > s1:
print("ture")
else:
print("false") #ASCII码值(十进制)
in
<pre name="code" class="python">st1 = "abcdef"
st2 = "ab"
st3 = "ce"
s = "abcdefghijklmnopqrstuvwxyz"
# 01234567890123456789012345
print(s)
print(s[6],s[14]) #输出g o
print(s[6]+s[14]) #输出go
i = 0
while i < len(s):
#print(s[i],end = "")
if s[i] == "g":
print("Find it!",s[i],i) #输出Find it! g 6
i += 1
if st2 in st1:
print("ture")
else:
print("false")
if st3 in st1:
print("ture")
else:print("false")
四、字符串的访问
3.1
index-索引
&
slice-切片
s = "abcdefghijklmnopqrstuvwxyz"
# 01234567890123456789012345
print(s)
print(s[6],s[14]) #输出g o
print(s[6]+s[14]) #输出go
i = 0
while i < len(s):
#print(s[i],end = "")
if s[i] == "g":
print("Find it!",s[i],i) #输出Find it! g 6
i += 1
练习:
#练习打印jeapedu000-jeapedu100
i = 0
while i <= 100:
if i == 0:
print("jeapedu000")
elif i < 10:
print("jeapedu00"+str(i))
elif i < 100:
print("jeapedu0"+str(i))
else:
print("jeapedu"+str(i))
i += 1