Day03(黑客成长日记)------>元祖及列表的增减改查

时间:2021-04-29 17:21:18
#昨日作业解析:

# s = 'sadagwa'
# i = 0
# while i < len(s):
# s1 = s[i]
# print(s1)
# i += 1
# while使用技巧,先找递增变量或者递减变量 #简单的加法计算器 print在输入多种元素时要用逗号隔开
# content = input('计算:').strip()
# s1 = content . split('+')
# num = 0
# for i in s1:
# num += int(i)
# print(num) # s = input('请输入:')
# count = 0
# s2 = s.split('abcd')
# for i in s2:
# if s2.isdigit:
# count = count+1
# print(count) #判断用户输入的数据中数字的个数代码
# s = input('请输入:')
# count = 0
# for i in s :
# if i .isdigit():
# count+= 1
# print(count) #
# s = input('请输入:')
# s2 = s.split(s.isalnum()) #23165 asdasd 321
# while :
# count = count #lise增删改查以及嵌套 # 1. append 增加到列表最后 # 公司整理人员名单输入代码 (利用增加)
# li = ['alex','wusir','tongsir','qienfseir','taige']
#
# while 1 :
# username = input('>>>>')
# if username.strip().upper()== 'Q':
# break
# else:
# li.append(username)
# print(li)
# print(li) # 2. insert 镶嵌 # li = ['alex','wusir','tongsir','qienfseir','taige']
# li.insert(4,'tong')
# print(li) # 3. extend list叠加是元素,用exte 迭代嵌套(int数据不可以) # li = ['alex','wusir','tongsir','qienfseir','taige']
# li.extend('同哥')
# print(li) #['alex', 'wusir', 'tongsir', 'qienfseir', 'taige', '同', '哥'] # 4.pop(索引) 删除元素 # li = ['alex','wusir','tongsir','qienfseir','taige']
# li.pop(1)
# print(li) #------------->输出['alex', 'tongsir', 'qienfseir', 'taige'] # li = ['alex','wusir','tongsir','qienfseir','taige']
# name = li.pop(1)
# print(name,li) #赋值的话会输出删除的元素,删唯一一个有返回值的用法,不填默认删除最后一个
#输出 wusir ['alex', 'tongsir', 'qienfseir', 'taige'] #
# 5.remove按照元素删除remove('yuansu') # 6.clean 清空列表 # 7.del li 删除li列表 del li[0:2] # 8.li[索引]='更改内容' # li = ['alex','wusir','tongsir','qienfseir','taige']
# li[0]='tongs'
# print(li) output = ['tongs', 'wusir', 'tongsir', 'qienfseir', 'taige']
#
#
# li[0:3] = [1,2,3,'sir','madom']
# print(li) output = [1, 2, 3, 'sir', 'madom', 'qienfseir', 'taige'] # 9 .查列表元素
# li = [1, 2, 3, 'sir', 'madom', 'qienfseir', 'taige']
# for i in li :
# print(i)
#
#
# output= 1
# 2
# 3
# sir
# madom
# qienfseir
# taige #10.列表排序(面试考)
# li = [1,2,5,8,4,7]
# li.sort() !=sort=正向排序
# print(li) output = [1, 2, 4, 5, 7, 8] # li = [1,2,5,8,4,7]
# li.sort(reverse=True) !=sorted(reverse=True)则反向排序
# print(li) output = [8, 7, 5, 4, 2, 1] #
li = [1,2,5,8,4,7]
# li.reverse() !=reverse()反转
# print(li) output = [7, 4, 8, 5, 2, 1] # li = ['taibai','武藤兰','yuanwu',['alex','89'],23]
# print(li[1][1])
# print(li[0].capitalize())
# li[0] = li[0].capitalize()
# print(li) # li[3][0]=li[3] [0].upper()
# print(li) #想改什么先找出来,操作完放回去。
#将上面的li中89改为100
# li[3][1]=int(li[3][1])+11
# print(li)
#
# li[3][1] = 100
# print(li) # 元祖tupe:只读列表,可以循环查询数据,但不可以修改,但是可以切片(儿子不能改,孙子可以改)(里面的元素不可以改,带里面的列表可以改,比如改下面的太白)
# tu = (1,2,3,'alex',[2,3,4,'taibai'],'egon')
# for i in tu:
# print(i) # 可以查询可以循环 #大写taibai
# tu[4][3]=tu[4][3].upper()
# print(tu) # #11. join的操作方法(可迭代对象)除了数字和bool返回的是字符串 # s = 'alex'
# s1 = ' '.join(s)
# print(s1) #output = a l e x #列表转换为Str用join,Str转换为list用str.split # #12. range 的用法
# for i in range(0,10,2):
# print(i)
#output = 0 2 4 6 8 # for i in range(10,0,-2):
# print(i)
# output = 10 8 6 4 2 # for i in range (0,10,-1)
# print(i) output = 不输入任何数据!!!!!!!!!!面试题 # li = [1,2,3,4,'alex',[2,3,4,5,'taibai'],'afds']
# count = 0
# num = 0
# if 1 :
# while count!=5 :
# s = li[count]
# print(s)
# count += 1
# if count ==6:
# continue
# while count ==5 :
# s1 = li[5][num]
# print(s1)
# num += 1
# if num >=5:
# count +=1
# while count!=5 :
# s = li[count]
# print(s)
# count += 1
# if count==7:
# break # for i in li:
# print(i)
# if i ==[2,3,4,5,'taibai']:
# for s in i:
# print(s)