
# yifan Python
class A:
pass
class B:
pass
class C(A,B):
def __init__(self,name,age):
self.name=name
self.age=age
#创建C类的对象
x=C('Jack',20) #x是C类型的一个实例对象
print(x.__dict__) #实例对象的属性字典
#{'name': 'Jack', 'age': 20}
print(C.__dict__) #C类型的属性
#{'__module__': '__main__', '__init__': , '__doc__': None}
print('----------------------------')
print(x.__class__)#输出对象所属类
#
##############查看继承那个类及哪些类##########################
print(C.__bases__)#C类的父类类型的元素
#(, )
print(C.__base__)#继承类
<class '__main__.A'>
print(C.__mro__) #类的层次结构
#(, , , )
# yifan Python
#特殊方法
a=20
b=100
c=a+b #两个类型的相加操作
d=a.__add__(b) #__add__()相加函数的操作
print(c)
print(d)
#120
#120
class Student:
def __init__(self,name):
self.name=name
def __add__(self, other):################## 实现字符串加法运算的方法
return self.name+other.name
def __len__(self):
return len(self.name)
stu1=Student('Jack')############################
stu2=Student('李四')#################################
s=stu1.__add__(stu2)
print(s)
print('------------------------------')
lst=[11,22,33,44]
print(len(lst))#len是内容函数 计算长度
print(lst.__len__()) #需要编写__len函数__
s=stu1+stu2
print(s)
# def __add__(self, other):
调用

传参








# yifan Python
############################模块的使用
import math #关于数学运算math模块
print(id(math))
print(type(math))
#2074877932336
#
print(math)
print(math.pi) #
#
#3.141592653589793
print('-------------------------------------------')
print(dir(math))#查看math模块的变量
print(math)
#['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']
#
print(math.pow(2,3),type(math.pow(2,3))) #math.pow()函数 次方函数
print(math.ceil(9.001))#
print(math.floor(9.999))
#8.0
#10
#9









# yifan Python
#Python 常用标准库
import sys
import time
import urllib.request
print(sys.getsizeof(24))
print(sys.getsizeof(45))
print(sys.getsizeof(True))
print(sys.getsizeof(False))
print(time.time())
#28
#28
#28
#24
#1666708043.7710903
print('---------------------------------')
print(time.localtime(time.time()))
#time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=22, tm_min=27, tm_sec=58, tm_wday=1, tm_yday=298, tm_isdst=0)
#爬虫库
print(urllib