python 2018/8/25
# 含多空格字符串的分割
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
python 2018/8/25