zoukankan      html  css  js  c++  java
  • 记录一下

     最近在复习Python, 好些不明白, 看到博主的文章试着练习了一下

    https://www.cnblogs.com/cookie1026/p/6937231.html

    第一题: 请使在3秒内计算出一组的数据,偶数在奇数前(注意不使用for while等循环的方法)

    data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    期望结果 [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]

    In [1]: data = [i for i in range(1,11)]
    Out[2]: data[1::2],data[::2] = data[::2],data[1::2]
    In [3]: data
    Out[3]: [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]

    第二题: 竖着打印输出如下格式(不要用第三方库):

    1 5 9   13

    2 6 10 14

    3 7 11 15

    4 8 12 16

    一开始一直不能并排输出, 想起来用end替换默认的换行

    for i in range(4):
        for j in range(1,17,4):
            print(i+j, end=' ') # end去掉默认的换行
        print('') # 每四个换一次行
  • 相关阅读:
    isalnum()方法
    index()方法
    find()方法
    expandtabs()方法
    endswith()方法
    encode()方法
    bytes.decode()方法
    count()方法
    center()方法
    capitalize()方法
  • 原文地址:https://www.cnblogs.com/luke20181010/p/10539108.html
Copyright © 2011-2022 走看看