# 含多空格字符串的分割

hello = "hello python hello"
print(a.split(" ")) # ['hello', 'python', '', 'hello']

print(hello.split())  # ['hello', 'python', 'hello']
print(len(a.split(" ")[2])) # ''也是一个字符串类型数据,只是什么都没有 # 0
print(a.split(" ")[2]) # 没有任何内容
print(type(a.split(" ")[2])) # <class 'str'> 字符串类型

# 字符串定义

hello = """hello python""" # hello python
hell0 = ""hello python"" # SyntaxError: invalid syntax

list1 = [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 list
list1.pop(-2)
print(list1)

# 关于del的两种删除方式
del list1[0]
print(list1)
del(list1[0])
print(list1)

#关于while的break

内循环里执行 break 不会导致外循环一起结束
j = 0
while 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                 continue
13             else:
14                 pass
15             while True:
16                 if active:
17                     tel = input("请输入手机号:(按q返回上一级)")
18                     if tel == 'q':
19                         break
20                     length_tel = len(tel)
21                     if length_tel != 11:
22                         print("长度不合法")
23                         continue
24                     else:
25                         pass
26                     while True:
27                         sex = input("请输入性别:(按q返回上一级)")
28                         if sex == 'q':
29                             break
30                         if sex == '' or sex == '':
31                             print("录入成功")
32                             active = False
33                         else:
34                             print("性别错误")
35                             continue
36                         print("*" * 5 + "名片信息" + "*" * 5)
37                         print("姓名:%s" % name)
38                         print("手机号: %s" % tel)
39                         print("性别:%s" % sex)
40                         break
41                 else:
42                     break
43         else:
44             break
45     ask = input("是否继续录入信息?y/n")
46     if ask == 'n':
47         print("谢谢使用V1.0")
48         break
View Code

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!