首页
Python
Java
IOS
Andorid
NodeJS
JavaScript
HTML5
【
Python3.6全栈开发实例[025]
】的更多相关文章
Python3.6全栈开发实例[025]
25.文件a1.txt内容(升级题)name:apple price:10 amount:3 year:2012name:tesla price:100000 amount:1 year:2013通过代码,将其构建成这种数据类型:[{'name':'apple','price':10,'amount':3},{'name':'tesla','price':1000000,'amount':1}......]并计算出总价钱. lst = [] sum = 0 with open('a','r',e…
Python3.6全栈开发实例[008]
8.有如下变量(tu是个元祖),请实现要求的功能:tu = ("alex", [11, 22, {"k1": 'v1', "k2": ["age", "name"], "k3": (11,22,33)}, 44])a.讲述元祖的特性 # 元祖是一个只读列表b.请问tu变量中的第一个元素 "alex" 是否可被修改? #不能被修改c.请问tu变量中的"k2&q…
Python3.6全栈开发实例[007]
7.此函数只接收一个参数且此参数必须是列表数据类型,此函数完成的功能是返回给调用者一个字典,此字典的键值对为此列表的索引及对应的元素.例如传入的列表为:[11,22,33] 返回的字典为 {0:11,1:22,2:33}. l2 = [11,22,33] def func8(l1): dic = {} for i in range(len(l1)): dic[i] = l1[i] return dic print(func8(l2)) l2 = [11,22,33] def func(lst):…
Python3.6全栈开发实例[006]
6.检查传入字典的每一个value的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者. dic = {"k1": "v1v1", "k2": [11,22,33,44]} PS:字典中的value只能是字符串或列表 dic = {"k1": "v1v1", "k2": [11,22,33,44]} def func(dic1): for i,j in dic1.ite…
Python3.6全栈开发实例[005]
5.接收两个数字参数,返回比较大的那个数字. def compare(a,b): return a if a > b else b # 三元表达式 print(compare(20,100))…
Python3.6全栈开发实例[004]
4.计算传入函数的字符串中, 数字.字母.空格以及其他内容的个数,并返回结果. s1 = 'wan%$#(gwdwq\nwdhuaiww3 w02041718' def func1(s1): dic = {'digit': 0, 'alpha': 0, 'space': 0, 'other': 0} for s in s1: if s.isdigit(): dic['digit'] += 1 elif s.isalpha(): dic['alpha'] += 1 elif s.isspace()…
Python3.6全栈开发实例[003]
3.检查传入列表的长度,如果大于2,将列表的前两项内容返回给调用者. li = [11,22,33,44,55,66,77,88,99,000,111,222] def func3(lst): if len(lst) > 2: return lst[:2] else: return lst print(func1(li))…
Python3.6全栈开发实例[002]
2.判断用户传入的对象(字符串.列表.元组)长度是否大于5. li = [11,22,33,44,55,66,77,88,99,000,111,222] def func2(lst): if len(lst) > 5: return True else: return False print(func2(li))…
Python3.6全栈开发实例[001]
检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者. li = [11,22,33,44,55,66,77,88,99,000,111,222] def func1(lst): new_li = [] for i in range(0,len(lst),2): new_li.append(lst[i]) return new_li print(func1(li))…
Python3.6全栈开发实例[027]
27.文件a.txt内容:每一行内容分别为商品名字,价钱,个数.apple 10 3tesla 100000 1mac 3000 2lenovo 30000 3chicken 10 3通过代码,将其构建成这种数据类型:[{'name':'apple','price':10,'amount':3},{'name':'tesla','price':1000000,'amount':1}......] 并计算出总价钱.''' import re lst = [] sum = 0 with open('…