zoukankan      html  css  js  c++  java
  • 声明式编程小练习

    # 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
  • 相关阅读:
    完整的 mime type 列表
    安装chrome扩展json-handle
    在没有go-pear.bat的php中安装pear
    windows下安装PhpDocumentor(phpdoc)笔记
    【MySQL】批量数据循环插入
    thinkPHP 3.2.3操作MongoDB指南
    给深度学习入门者的Python快速教程
    为什么人工智能用Python
    计算机英语(一)
    Java 基础生词表
  • 原文地址:https://www.cnblogs.com/0B0S/p/11997656.html
Copyright © 2011-2022 走看看