int(x)float(x)complex(x)、complex(x,y)bool(x)round() 四舍六入,五取偶int() 取整,和//整除一样floor() 取小、ceil() 取大import mathtype(obj) 返回类型,不是字符串isinstance(obj,clsaa_or_tuple) 返回布尔值type(1+True+2.0) 隐式转换.randint(a,b) 返回[a,b] 之间的整数.choice(seq) 从非空序列的元素中随机挑选一个元素.randrange([start,] stop[,step]) 从指定范围内按指定基数递增的集合中获取一个随机数,基数的缺省值为1random.shuffle(list) 就地打乱列表元素sequence[start:stop]返回[start:stop)区间的子序列[:]从头到尾全部元素被取出,等效于copy() 方法[start:stop:step]封装
将多个值使用逗号分割,组合在一起
本质上返回一个元组,只是省略了小括号
python特有语法,被很多语言学习借鉴
举例:
t1 = (1,2) #定义元组
t2 = 1,2 #将1,2封装成元组
type(t2) #tuple
解构
把线性结构的元素解开,并顺序赋值给其他变量
左边接纳的变量要和右边解开的元素个数一致
举例:
lst = [3,5]
a,b = lst
丢弃变量
id()
hash()type()float()、 int() 、bin() 、hex() 、oct() 、bool() 、list() 、tuple()、 dict()、 set() 、complex() 、bytes()、bytearray()input([prompt])print(*objects,sep=‘‘,end=‘\n‘,file=sys.stdout,flush=False)
len()isinstance(obj,class_or_tuple)
isinstance(True,int)issubclass(cls,class_or_tuple)
issubclass(bool,int)abs(x)max() 、min()
round(x)pow(x,y)
x**yrange(stop)divmod(x,y)
tuple(x//y,x%y)sum(iterable[,start])
chr(i)ord(c)str()repr()ascii()原文:https://www.cnblogs.com/wanghonghao/p/12578591.html