1、字符串
mystring = "goodmoring"
print("mystring[0]",mystring[0])
print("mystring[2:7]",mystring[2:7])
结果:
个人理解:
mystring[0] ='g' mystring[2]='o' mystring[7]='n'
其中mystring[2:7] 说的是2开始的值到7的值 其中7是不包括的(自行理解)
所以 mystring[2:7]就是输出 'odmor'
拓展:
mystring = "goodmoring"
print("mystring:%s"%mystring)
print("mystring[0]",mystring[0])
print("mystring[2:7]",mystring[2:7])
print("mystring[0:7]",mystring[0:7])
print("mystring[:]",mystring[:])
print("mystring[0:]",mystring[0:])
print("mystring[2:]",mystring[2:])
print("mystring[:8]",mystring[:8])
print("mystring[:4]",mystring[:4])
输出结果
2、条件语句
1、if-else语句
mystring ='goodafternoon'
if 'a' in mystring:
print("true")
else:
print("fault")
输出结果
拓展:
mystring ='goodafternoon'
if 'z'in mystring:
print("fault-1")
elif 'y' in mystring:
print("fault-2")
elif 'e' in mystring:
print("good")
else:
print("bad")
输出结果
2、while语句
myint = 10
while myint != 2:
print("now myint:%d"%myint)
myint = myint - 1
输出结果
拓展:
myint = 10
while myint != 2:
print("now myint:%d"%myint)
myint = myint - 1
if myint == 9:
print("*********")
elif myint == 8:
print("********")
elif myint == 7:
print("*******")
elif myint == 6:
print("******")
else:
print("∝")
输出结果
以上记录于2021年5月27日