zoukankan      html  css  js  c++  java
  • 小的面试题

    • 如何用一行代码生成[1,4,9,16,25,36,49,64,81,100]
    l = [i **2 for i in range(1,11)]
    print(l)
    • and:前后为真才为真
      or:有一为真就为真
      优先级:()>not>and>or
      同等优先级下,从左向右

      v1 = 1 or 3  
      v2 = 1 and 3 
      v3 = 0 and 2 and 1 
      v4 = 0 and 2 or 1 
      v5 = 0 and 2 or 1 or 4 
      v6 = 0 or Flase and 1   
      1
      3
      0
      1
      1
      False
    • 高阶函数:map()

      根据函数对指定序列做映射
      map()函数接收两个参数,一个是函数,一个是可迭代对象,map将传入的函数依次作用到序列的每个元素,并把结果返回
      返回值:
        (Python2 返回列表  Python3 返回迭代器)
      

    1. 想得到一个:[1, 4, 9, 16, 25]的列表
    def mul(x):
        return x*x
    n=[1,2,3,4,5]
    res=list(map(mul,n))
    print(res)
    1. 想要得到[-1,-5,6,-7]返回数字的绝对值
    res1 = map(abs,[-1,-5,6,-7])
    print(list(res1))

        

  • 相关阅读:
    react注意事项
    小程序的页面滚动
    calc
    写好的vue项目怎么打包成uniapp形式
    处理其他系统过来的token.
    解析token
    iframe接受不同域名的token
    tree懒加载的使用,
    js防抖节流
    vue2.0和vue3.0的区别
  • 原文地址:https://www.cnblogs.com/ZHang-/p/10173516.html
Copyright © 2011-2022 走看看