name =' kk loving 999 shuijiao 12 34'
print(name.strip('2 431'))
print(name.split())
for i in name:
print(i,end='')
真年龄
age = 18
count = 0 #计数
prize = {0:'苹果',1:'香蕉',2:'橘子',3:'西瓜',4:'樱桃'}
while count < 3:
inp_age = input('输入年龄>>>').strip() #交互
#判断数字
if inp_age.isdigit():
inp_age_int = int(inp_age)
#判断大小
#对了
if age == int(inp_age_int):
#选奖励
prize_choice=int(input((f'正确的,请选择奖励:{prize}')))
print(f'恭喜获得{prize[prize_choice]}')
print('游戏结束')
break
#错了
elif age > int(inp_age_int):
print('小了')
else:
print('大了')
#不是数字
else:
print('请输入数字')
count += 1 # 计数+1
#3次后选择
if count == 3:
choice = input('是否继续?“y”/“n”')
if choice == 'y':
count = 0
elif choice == 'n':
break
else:
print("输错了")
break
列表类型
list = ['苹果','香蕉','橘子','西瓜','樱桃','葡萄']
print(list)
list.append('taozi')
print(list)
del list[-1]
print(list)
list.insert(1,'liulian')
print(list)
list.pop()
print(list)
list.remove('西瓜')
print(list)
list.count('苹果')
list.index('苹果')
list.clear()
print(list)
list = ['苹果','香蕉','橘子','西瓜','樱桃','葡萄']
print(list.copy())
list.extend(['taozi','liulian','shuijiao'])
print(list)
list.reverse()
print(list)
list.sort()
print(list)
import random
print(random.randint(1,100))
元组
tupl1= tuple([1,2,3,4,5,6,7,8,9,10])
print(tupl1[2:])