# 含多空格字符串的分割
hello = "hello python hello"
print(a.split(" ")) # ['hello', 'python', '', 'hello']print(hello.split()) # ['hello', 'python', 'hello']
print(len(a.split(" ")[2])) # ''也是一个字符串类型数据,只是什么都没有 # 0print(a.split(" ")[2]) # 没有任何内容print(type(a.split(" ")[2])) # <class 'str'> 字符串类型# 字符串定义
hello = """hello python""" # hello python
hell0 = ""hello python"" # SyntaxError: invalid syntaxlist1 = [10,3.13,'hello',True]
list1.append(3)print(list1)list1[2] = '你好'
print(list1)list1.remove('你好')print(list1)# list1.remove('nihao') # ValueError: list.remove(x): x not in listlist1.pop(-2)print(list1)# 关于del的两种删除方式
del list1[0]print(list1)del(list1[0])print(list1)#关于while的break
内循环里执行 break 不会导致外循环一起结束
j = 0while j < 3: print("外层运行中") i = 0 while i < 6: if i ==4: break print("内层运行中") i += 1 if j ==2: break j += 1名片管理系统
1 while True: 2 print("欢迎使用ITV1.0") 3 active = True 4 while True: 5 if active: 6 name = input("请输入姓名:(按q退出)") 7 if name == 'q': 8 break 9 length_name = len(name)10 if (length_name < 6) or (length_name > 20):11 print("长度错误")12 continue13 else:14 pass15 while True:16 if active:17 tel = input("请输入手机号:(按q返回上一级)")18 if tel == 'q':19 break20 length_tel = len(tel)21 if length_tel != 11:22 print("长度不合法")23 continue24 else:25 pass26 while True:27 sex = input("请输入性别:(按q返回上一级)")28 if sex == 'q':29 break30 if sex == '男' or sex == '女':31 print("录入成功")32 active = False33 else:34 print("性别错误")35 continue36 print("*" * 5 + "名片信息" + "*" * 5)37 print("姓名:%s" % name)38 print("手机号: %s" % tel)39 print("性别:%s" % sex)40 break41 else:42 break43 else:44 break45 ask = input("是否继续录入信息?y/n")46 if ask == 'n':47 print("谢谢使用V1.0")48 break