• 基础题整理


    1.编译型语言和解释性语言的区别?

      编译型:编译后再执行...代表语言有:C,Java,C#

      解释性语言:边解释变执行...代表语言有:python,PHP

    2.运算符总结:

      ①:顺序:括号>not>and>or

      ②:规则:and前后都为真才为真,or前后有一个为真就为真

      ③:取值:and前后都不为0的情况,取后面的值,and前面为0时取0位最终值.

          or前后不为0的情况下,取后面的值,or前面为0时 取后面的值为最终值

      ④:括号与布尔结合: c=1 < (2==2) #False      d=1 < 2 == 2 #True

    3.数据类型:以及每个的5个方法:

      ①:str(字符串)  :split(分割)-->strip(去掉两边的空格)-->upper(大写)-->startwith(以什么开头)-->endwith(以什么结尾)-->lower(小写)

      ②list(列表): append(追加)-->insert(插入)-->index(索引)-->server(排序)-->pop(删除,加索引删除指定索引,不加默认删除最后一个)

      ③dict(字典):get(根据key获取value的值)-->items(用于循环,取出所有key和value)-->keys(去除key的所有值)-->values(去除value所有的值)-->pop(删除)

      ④tuple(元组):Count:查看某个元素出现的次数-->Index:索引

    4;参数陷阱:

      def func(a,b=[])  这种写法的陷阱:

      列表是可变数据类型,可能会在过程中修改里面的值

     

    5;装饰器 & 带参数的装饰器(带参数的装饰器可以使函数执行任意次)

    """
    def counter(num):
    def outer(f):
    def inner(*args,**kwargs):
    rets = []
    for i in range(num):
    ret = f(*args,**kwargs)
    rets.append(ret)
    return rets
    return inner
    return outer
    @counter(3)
    def func():
    print('1111')

    rets = func()
    print(rets)
    """
    6:yield &yield from (节省内存空间)
    yield使用 
    1)函数中使用yield,可以使函数变成生成器。一个函数如果是生成一个数组,就必须把数据存储在内存中,如果使用生成器,则在调用的时候才生成数据,可以节省内存。
    2)生成器方法调用时,不会立即执行。需要调用next()或者使用for循环来执行。
    yield from的使用:
    1)为了让生成器(带yield函数),能简易的在其他函数中直接调用,就产生了yield from。 
    """
    def foo():
    yield 55
    yield 66

    def func():
    yield 1
    yield from foo()
    yield 2
    yield 3
    r1 = func()
    for i in r1:
    print(i)
    """

     7;列表生成式

    # v1 = [ i for i in range(10)]
    # v2 = [ lambda :i for i in range(10)] 匿名函数
    # def func():
    # return i
    # func_list = []
    # for i in range(10):
    # func_list.append(func)
    # x = func_list[5]()
    # print(x)

    8;py2和py3的区别:
    ①:
    默认解释器编码:py2-> ascii ; py3->utf-8
    ②:字符串和字节 py2:unicode str=bytes
             py3:str字符串 bytes:字节
    ③经典类和新式类:py2:经典类和新式类(直接或间接继承object)
             py3:新式类

    9;你用过的内置模块有哪些:
    os(
    使用操作系统函数)--re(正则)--time&datetime(时间模块)--random(随机数模块)--json(序列化)--hashlib(加密模块)
    --logging(日志模块)--pickle(序列化)

    10第三方模块;
    requests,bs4,pymysql,pymongo,gevent(gevent是可以很轻松地将它的网络模型分布到多个进程并行处理的。)
    安装:pip install 软件名

    11常见的双下划线方法:
     __call__
    __new__
    __dict__
    __setattr__
    __getattr__
    __delattr__
    __getitem__
    __setitem__
    __delitem__
    __iter__
    __enter__
    __exit__

    __init__
    __str__
    __repr__
    __del__

    12:单例模式:
      ①什么是单例模式;单例模式是一种设计模式,是指一个类仅仅能有一个实例。
      ②
    哪里使用单例模式?:django admin 数据库连接池
    单例模式的书写:

    
    
    推荐:

    import threading
    import time

    class Foo(object):
    _instance = None
    _lock = threading.RLock()

    def __new__(cls, *args, **kwargs):
    if cls._instance:
    return cls._instance
    with cls._lock:
    if not cls._instance:
    cls._instance = object.__new__(cls)
    return cls._instance
    def task():
    obj = Foo()
    print(obj)
    for i in range(10):
    t = threading.Thread(target=task)
    t.start()

    time.sleep(100)
    obj = Foo()
     
     
     


  • 相关阅读:
    [App Store Connect帮助]七、在 App Store 上发行(3.2)提交至“App 审核”:查看 App 状态历史记录
    [App Store Connect帮助]七、在 App Store 上发行(3.1)提交至“App 审核”:提交 App 以供审核
    (1.2)DML增强功能-4大排名函数与top ties/tablesample
    (1.1)DML增强功能-CTE
    CTE的妙用
    sql server 统计信息
    oracle高水位问题
    查看慢查询语句
    关于uuid与自增列的选择
    sql server学习路径地址
  • 原文地址:https://www.cnblogs.com/cz007/p/10186130.html
Copyright © 2020-2023  润新知