#作業回顧s = 11 s1 = s.bit_length() print(s1) s = bool() print(s) s = 'bhsdjshfa' s3 = s[2::-2] print(s3) a = 'abisdugs' for i in a : print(i) #字元串的拼接可以通過... ...
#作業回顧
s = 11 s1 = s.bit_length() print(s1) s = bool() print(s) s = 'bhsdjshfa' s3 = s[2::-2] print(s3) a = 'abisdugs' for i in a : print(i)
#字元串的拼接可以通過+實現
s = 's132jsdihfsd' s1 = s[1]+s[3]+s[2] print(s1) a = 'abisdugs'
#while 實現遍歷
s = 's132jsdihfsd' index = 0 while 1: print(s[index]) index += 1 if index == len(s): break
#輸入個位數+個位數 實現求和(包括一個字元串轉換)
content = input('>>>').strip() index = content.find("+") a = int(content[0:index]) b = int(content[index:]) c = a + b print(c)
# 求和對單個或多個數字進行求和。 content = input(">>>").strip() col1 = content.split('+') sum = 0 for i in col1: sum += int(i) print(sum) #用戶輸入一系列數字字母,輸出數字個數 text = input('>>>') count = 0 for i in text: if i.isdigit(): count += 1 print(count) #等級信賴員工名字,按q輸入。 li = [1,'a','b',2,3,'a'] while 1: username = input('>>>') if username.strip().upper() == 'Q': break else: li.append(username) print(li)
#對列表進行增刪改查
增加 指定位置 li.insert(4,'lskud h') print(li) li.extend('二哥') li.extend([1,2,34,5]) print(li) li = [1,'a','b',2,3,'a'] li.pop(1) name = li.pop() print(name,li) 刪 li.remove('a') print(li) # li.clear() print(li) del li[2:] #切片刪除 print(li) #改 li[0] = '男爵' print(li) li[0:2]='yuandsaa' print(li) #查 for i in li : print(i) l = len(li) print(l) s = li.count('d') print(s) print(li.index('d')) 排序 li = [1,324,6,5,765,342,3] #sort()正向排序 li.sort() print(li) #倒序 li.sort(reverse=True) print(li) #反轉 li.reverse() print(li)