码迷,mamicode.com
首页 > 其他好文 > 详细

声明式编程小练习

时间:2019-12-06 21:16:11      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:object   ice   back   ali   obj   most   value   last   小练习   

# names=[‘OBOS‘,‘age‘,‘Alice‘]
# l=[]
# for name in names:
# name=name.upper()
# l.append(name)
#
# print(l) # [‘OBOS‘, ‘AGE‘, ‘ALICE‘]
#
# names=[‘OBOS‘,‘age‘,‘Alice‘]
# l=[]
# for name in names:
# name=name.upper()
# l.append(name)
#
# names=l
# print(names) # [‘OBOS‘, ‘AGE‘, ‘ALICE‘]

# names=[‘OBOS‘,‘age‘,‘Alice‘]
# names=[name.upper()for name in names]
# print(names) # [‘OBOS‘, ‘AGE‘, ‘ALICE‘]

# names=[‘OBOS‘,‘age‘,‘Alice‘]
# s=[name for name in names if name.endswith(‘ge‘)]
# print(s) # [‘age‘]

# obj=list(‘qwertyuio‘)
# print(obj) # [‘q‘, ‘w‘, ‘e‘, ‘r‘, ‘t‘, ‘y‘, ‘u‘, ‘i‘, ‘o‘]

# print(max([1,2,3,4,5,6,7,8])) # 8

# g=(i for i in range(10))
# print(max(g))
# print(max(g))
‘‘‘
Traceback (most recent call last):
9
File "D:/text/声明式编程小练习.py", line 33, in <module>
print(max(g))
ValueError: max() arg is an empty sequence
‘‘‘
# g=(i for i in range(10))
# print(max(g))
# g=(i for i in range(10))
# print(max(g))
‘‘‘
9
9
‘‘‘
# with open(‘b.txt‘,‘r‘,encoding=‘utf-8‘) as f:
# l=[]
# for line in f:
# # print(len(line))
# l.append(len(line))
#
# print(l)
# print(max(l))
‘‘‘
[23, 11, 17, 17, 161, 17, 17, 17, 17, 17, 17, 17, 17, 17, 1]
161
‘‘‘
# with open(‘b.txt‘,‘r‘,encoding=‘utf-8‘) as f:
# l=[len(line) for line in f]
# print(max(l)) # 161
# with open(‘b.txt‘,‘r‘,encoding=‘utf-8‘) as f:
# l=(len(line) for line in f)
# print(l)
# print(max(l))
‘‘‘
<generator object <genexpr> at 0x0000021C4BBFE7C8>
161
‘‘‘
# with open(‘b.txt‘,‘r‘,encoding=‘utf-8‘) as f:
# # # l=(len(line) for line in f)
# # # print(l)
# # # print(max(l))
# # print((len(line) for line in f))
# # print(max(l))
# print(max(len(line) for line in f)) # 161

# with open(‘b.txt‘,‘r‘,encoding=‘utf-8‘) as f:
# # print(sum([len(line) for line in f])) # 383
# print(sum(len(line) for line in f)) # 383

声明式编程小练习

标签:object   ice   back   ali   obj   most   value   last   小练习   

原文地址:https://www.cnblogs.com/0B0S/p/11997656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!