首页 > 其他 > 详细

基础复习

时间:2020-02-06 09:37:48      阅读:146      评论:0      收藏:0      [点我收藏+]
#简述编程语言与语言之间的区别
# 1.# python简单,python开发效率快,python代码简介,python跨平台,python学习成本比较低

# 2.列举Python2Python3的区别?
# py3
# print()
# unicode
# 类:新式类
# range() -- 可迭代对象
# input() -- 获取的内容全都是字符串
# 除法 -- 浮点数
# readlines() -- 列表
# 没有long(长整型)


# py2
# print
# ascii
# 类:金典类,新式类
# range() -- 列表
# xrange() -- 可迭代对象
# raw_input() -- 获取的内容全都是字符串
# input() “alex”
# 除法 -- 整数
# xreadlines -- 返回一个迭代器

# 3.
# 1 7

# 4. 两个列表,一个列表中是元组

# 5.
# ab = ba

# 6. 标准:三引号可以进行换行,单引号和双引号需要配合使用

# 7.
# is 判断的是两边的内存地址
# == 判断的是两边的值

# 8.
# tuplelist
# listtuple

# 9.
# name=‘老男孩
# print(name[::-1])

# 10.两个set如何获取交集、并集、差集?
# &
# |
# -

# 11.那些情况下, y != x - (x-y)会成立?
# x = {2}
# y = {1}
# print(y != x - (x-y))
# 两个非空的集合,并且集合中的元素不能相同,并且也不能是x的子集

# 12.
# lst = [1,2,3,4,5,6,7]
# import copy
# lst3 = lst.copy() # 浅拷贝
# lst1 = copy.copy(lst) # 浅拷贝
# lst2 = lst[:] # 浅拷贝

# 13.
# 赋值: 多个变量指向同一内存地址
# a = 10
# b = a
# c = b
# a = 10 + 5
# print(a,b,c) # 15 10 10

# # 浅拷贝:
# lst = [1,2,3,4,[5,6,],78]
# lst1 = lst[:]
# lst1.append(0)
# print(lst1) # [1,2,3,4,[5,6,],78,0]
# print(lst) # [1,2,3,4,[5,6,],78]

# 浅拷贝:
# lst = [1,2,3,4,[5,6,],78]
# lst1 = lst[:]
# lst1[-2].append(0)
# print(lst1) # [1,2,3,4,[5,6,0],78,0]
# print(lst) # [1,2,3,4,[5,6,0],78]

# # 浅拷贝:
# lst = [1,2,3,4,[5,6,],78]
# lst1 = lst[:]
# lst1[-2] = 12
# print(lst1) # [1,2,3,4,12,78,0]
# print(lst) # [1,2,3,4,[5,6,0],78]

# 浅拷贝:
# lst = [1,2,3,4,[5,6,],78]
# lst1 = lst[:]
# lst[-2] = 12
# print(lst1) # [1,2,3,4,[5,6],78,0]
# print(lst) # [1,2,3,4,12,78]

# 浅拷贝: 只拷贝第一层元素的内存地址

# 深拷贝:
# import copy
# lst = [1,2,[3,4],5]
# lst1 = copy.deepcopy(lst)
# lst.append(10)
# print(lst) # [1,2,[3,4],5,10]
# print(lst1) # [1,2,[3,4],5,]

# import copy
# lst = [1,2,[3,4],5]
# lst1 = copy.deepcopy(lst)
# lst[-2].append(10)
# print(lst) # [1,2,[3,4,10],5,]
# print(lst1) # [1,2,[3,4],5]

# import copy
# lst = [1,2,[3,4],5]
# lst1 = copy.deepcopy(lst)
# lst[-2] = 52
# print(lst) # [1,2,52,5,]
# print(lst1) # [1,2,[3,4],5]

# import copy
# lst = [1,2,[3,4,[1,[]]],5]
# lst1 = copy.deepcopy(lst)
# lst[-2] = 52
# print(lst) # [1,2,52,5,]
# print(lst1) # [1,2,[3,4],5]

import copy

# dic = {"key":[12,23]}
# dic1 = dic.copy()
# dic["key"].append(15)
# print(dic)
# print(dic1)

# 深拷贝,不管嵌套多少层.不可变数据类型共有,可变数据类型开辟新的空间
# 16 python打印9*9乘法表
# 17.使用列表实现斐波那契
# Python显示一个斐波那契数列
# lst = [1,1]
# for i in range(100):
# lst.append(lst[-1] + lst[-2])
# print(lst)

# a = dict(zip(("a","b","c","d","e"),(1,2,3,4,5)))
# print(dict([(1,2),(3,4)]))
# print(dict(a=1,b=2,c=3))

# lambda def
# print((lambda x:x)(15))

# 22.*arg``**kwarg`作用?
# *args : 接收多余位置参数,以元组的形式显示, 可以修改名字,但是不建议修改
# **kwargs: 接收多余关键字参数,以字典的形式显示

# 23.
# global

# 24.
# lst = [1,2,3,4,5,6,7,8,9]
# def func(x):
# return x > 5

# print(list(filter(func,lst))) # 高阶函数 -- 帮咱们实现了一个for循环

# 模拟filter
# def foo(x):
# """指定过滤的规则"""
# return x > 5
#
# def f(func,iter):
# lst = []
# for i in iter:
# if func(i):
# lst.append(i)
# return lst
#
# print(f(foo,[1,2,3,4,5,6,7,8,9]))

# print(list(map(str,[3,4,5,5,6,7]))) # 映射

# from functools import reduce
# print(reduce(lambda x,y:x*y,[1,2,3,4,5]))

# Python递归的最大层数?
# 官方:1000
# 实际测试:998

# 什么是迭代器?什么是可迭代对象?
# 迭代器: 具有__iter____next__的就是迭代器
# 可迭代对象: 具有__iter__方法的就是可迭代对象

# iter() __iter__()
# next() __next__()

# 什么是生成器?
# 生成器的本质的就是迭代器,函数体出现yield就是生成器

# 区分生成器和迭代器:
# 1.通过内存地址
# 2.通过send()方法

# 什么是装饰器及应用场景?
# 装饰器:在不改变原函数的代码以调用方式,额外增加一些功能
# 装饰器:
# django - 中间件
# 面向对象
# flask路由 -- 有参装饰器
# 自定义登录系统

# 什么是反射及应用场景?
# 反射:通过字符串的方式调用对象
# 应用场景:
# ....

# 写一个普通的装饰器。 pass
# 写一个带参数的装饰器。 pass

# def auth(argv):
# def wrapper(func):
# def inner(*args, **kwargs):
# if argv:
# print("我来了")
# func(*args, **kwargs)
# print("wo zou le")
# else:
# func(*args, **kwargs)
# return inner
# return wrapper
#
# @auth(False)
# def foo():
# print(11)
#
# foo()

# def num():
# return [lambda x:i*x for i in range(4)]
# print([m(2) for m in num()])
# [6,6,6,6]
import random

"""
10.3.9.12 转换规则为
10 00001010
3 00000011
9 00001001
12 00001100

以上二接起来计算十果:00001010 00000011 00001001 00001100 =
"""
# ip = "10.3.9.12"
# s = ""
# for i in ip.split("."):
# s += format(int(i),"08b")
# print(int(s,2))

# ip = "10.3.9.12"
# import socket,struct
# print(struct.unpack("!I",socket.inet_aton(ip))[0])

# import math # 数学
# print(math.floor(5.9)) # 地板 向下取整
# print(math.ceil(4.1)) # 天花板 向上取整

# rematchsearch区别?
# match 从头开始匹配,匹配到第一个就停止了
# search 从任意位置进行匹配,匹配到第一个就停止了

# Python匹配HTML tag的时候,<.*><.*?>有什么区别?

# random.random()
# random.randint(1,5)
# print(random.randrange(1,20,2))
# print(random.choice([1,2,3,4,5]))
# print(random.choices([1,2,3,4,5],k=5))
# print(random.sample([1,2,3,4,5],k=5))
# random.shuffle([1,2,3,4,5])

# super() 按照mro的顺序进行继承

# 双下划线和单下划线的区别?
# 双下划线 -- 魔法方法(双下方法)
# 单下划线 -- 私有方法 私有方法不能进行继承

# @staticmethod@classmethod的区别
# @staticmethod : 静态方法
# @classmethod : 类方法

# 实现一个单例模式 (加锁)

# 栈和队列的区别?

# class Parent(object):
# x = 1
#
# class Child1(Parent):
# pass
#
# class Child2(Parent):
# pass
#
# print(Parent.x, Child1.x, Child2.x)
#
# Child1.x = 2
# print(Parent.x, Child1.x, Child2.x)
#
# Parent.x = 3
# print(Parent.x, Child1.x, Child2.x)

# class Context: # 上下文管理
#
# def do_something(self):
# print(111)
#
# def __enter__(self):
# return self
#
# def __exit__(self, exc_type, exc_val, exc_tb):
# pass
#
# with Context() as ctx:
# ctx.do_something()

# 请在Context类下添加代码完成该类的实现


# lst = [1,2,[]] * 3
# lst[-1].append(10)
# print(lst)


# def wrapper(func):
# def inner(*args,**kwargs):
# print("is 123")
# func(*args,**kwargs)
# print("345")
# return inner
#
# def wrapper1(func):
# def inner1(*args,**kwargs):
# print("7")
# func(*args,**kwargs)
# return inner1
#
# def wrapper2(func):
# def inner2(*args,**kwargs):
# func(*args,**kwargs)
# print("15")
# return inner2
#
# @wrapper2
# @wrapper1
# @wrapper # foo = wrapper(foo)
# def foo(): # 先执行里被装饰函数最近的那个装饰器
# print("is foo")
#
# foo()

基础复习

原文:https://www.cnblogs.com/duhong0520/p/12267526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!