zoukankan      html  css  js  c++  java
  • 假期(面试题二)

    # 1、如何得到列表list的交集与差集
    # lis1 = [1,2,3,4,5]
    # lis2 = [1,2,3,4,5,6,7]
    # 差集
    # ret_list = []
    # for item in lis2:
    #     if item not in lis1:
    #         ret_list.append(item)
    # print(ret_list)
    # res_list = list(set(lis1)^set(lis2))
    # 交集
    # 先将他俩变成集合,然后集合求交集
    
    
    # 2、以下代码的输出结果是什么
    # def extend(val,list=[]):
    #     list.append(val)
    #     return list
    # list1 = extend(10)
    # list2 = extend(123,[])
    # list3 = extend("a")
    # print(list1)    #[10, 'a']
    # print(list2)    #[1,2,3]
    # print(list3)   #[10, 'a']
    
    # 3、python中定义函数时如何书写可变参数和关键字参数
    #  函数的参数位置:位置参数,默认参数,关键字参数,可变参数
    # 4、什么是lambda表达式
    # lambda表达式也是一个函数,不过他的作用是一次性的,定义一次使用一次,lambda只需要写一行
    # 5、re和match()和search()有什么区别
    # re.match()是匹配所有,返回列表,re.search()只是匹配一个,匹配到一个立马返回
    # 6、1 or 2和1 and 2输出的分别是什么,为什么
    # 1 or 2返回1,因为1位True,不在往后看,如果是and,第一个为真还要看第二个,第二个为真返回第二个
    # 7、1 < (2 == 2)和1 < 2 == 2的结果分别是什么?为什么?
    # 1 < (2 == 2)   2==2为真,返回1,1<1为False,,1 < 2 == 2  1<2返回True
    # 8、[i%2 for i in range(10)] 和 (i%2 for i in range(10))的输出结果分别是什么
    # [i%2 for i in range(10)]   =======> [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
    # (i%2 for i in range(10))   =======>返回一个生成器对象
    # 9、请描述unicode、utf - 8、gbk等编码之间的关系
    # 内存中的数据都是unicode形式存在的,要想将它持久化到硬盘则必须转换为utf-8或者gbk等编码
    #  unicode  --> encode(utf-8)   ---> bytes    unicode经过encode讲过utf-8编码之后转换为bytes
    # bytes  ---> decode(gbk)  ----> unicode      bytes经过decode经过gbk解码之后变为unicode
    # 10、def f(a,b=[]) 这种写法有什么陷阱
    # 如果只是传入位置参数没问题,但是传入默认参数就会出现一点点的小问题
  • 相关阅读:
    洛谷-P5357-【模板】AC自动机(二次加强版)
    洛谷-P3796-【模板】AC自动机(加强版)
    洛谷-P3808-【模板】AC自动机(简单版)
    2020 CCPC Wannafly Winter Camp Day2-K-破忒头的匿名信
    zabbix的搭建
    playbook 介绍
    ansible 模块
    shell 脚本判断ip
    shell 脚本安装lnmp
    expect 介绍
  • 原文地址:https://www.cnblogs.com/52-qq/p/8448518.html
Copyright © 2011-2022 走看看