1、数学运算类

# 1、数学运算类

# abs:计算绝对值
print(abs(-23)) # divmod,返回一个tuple,第一个值为商,第二个值为余数
print(divmod(10,4)) # float:将一个字符串或者整数转换为小数
print(float(23)) print(float("3")) print(int(3.1))
# 转换一个小数为整数 print(int("10",base=8))
# 将一个8进制的数转换为10进制,这里的8意思就是10这个字符串指定的数字为8进制,这里要注意,10这里必须要用字符串的方式传入 print(pow(3,3))
# 计算3的3次方 range(1,10,3)
# 返回一个range对象,起始为1,结尾为10,但是不包括10,步长为3 print(round(2.146,1))
# 四舍五入,第二个参数为保留的小数位 print(sum([1,2,3,4,5]))
# 传入一个序列,计算这个序列所有元素的和 print(bin(10))
# 计算一个数字的二进制 print(oct(10))
# 计算一个数字的八进制 print(hex(10))
# 计算一个数字的16进制 print(chr(98))
# 返回一个整数对应的ASCII码 print(bool(0))
print(bool(1))
# 返回一个对象的的布尔值

2、集合类操作

# 集合类操作

# format()
# 用来格式化字符串的 for m,n in enumerate(range(10),1):
print(m,n,sep=":") # 1:0
# 2:1
# 3:2
# 4:3
# 5:4
# 6:5
# 7:6
# 8:7
# 9:8
# 10:9
# print(max([10,4,3,233,4]))
# 计算一个序列的最大值 print(min([10,4,3,233,4]))
# 计算一个序列的最小值 print(sorted([10,4,3,233,4],reverse=True))
# 逆序排列 print(sorted([10,4,3,233,4],reverse=False))
# 正序排列 def test(k):
return k[1] d = {"a":23,"b":45,"c":1} res = sorted(d.items(),key=test)
# 将一个序列中的每个元素作为参数传递给test函数,然后根据test的函数的返回值做排序 print(res)

3、逻辑判断

# 3、逻辑判断

print(all([1,0,True,False]))
# 序列中所有为真才为真 print(any([1,0,True,False]))
# 序列中有一个为真则为真

4、反射类

print(callable(str))

print(callable(1))

print(callable(test))

# 判断一个对象是否可以被调用/执行,类是可以被调用的,实例是不可以被调用的,除非定义了__call__方法

# classmethod
# 装饰器,在一个类中定义的方法转换为类的方法,使用类对象可以直接调用该方法 class Test(object): @classmethod
def test_1(cls):
print("这是一个类方法") Test.test_1() print(dir(str))
# 返回对象所具有的方法和属性 # 反射的4个方法
# hasattr()
# 判断某个对象是否有指定的属性或者方法
# delattr()
# getattr()
# setattr() class Test2(object):
def __init__(self,name):
self.name = name
def test_1(self):
print("这是一个实例的方法") print(hasattr(Test2,"test_1"))
print(hasattr(Test2,"test_2")) print(hasattr(Test2,"name"))
# 类没有name这个属性或者方法 t = Test2('cui')
print(hasattr(t,"name"))
# 类的实例有name这个属性和方法 r = getattr(t,"name")
print(r)
# 获取属性的地址 r = getattr(t,"test_1")
r()
# 获取方法的地址,并执行 # filter()
# 过滤器 l = [12,4,5,7,5,44,7,5,7] def test2(num):
if num > 10:
return True print(list(filter(test2,l))) def test3(num):
return num + 100 print(list(map(test3,l))) # id
# 返回内存地址 # isinstance
# 判断实例是否为类的实例 print(isinstance("12",str))
print(isinstance("12",bool)) # issubclass()
# 判断某个类是否为类的子类 class Test3(object):
def __init__(self,name):
self.name = name class Test4(Test3):
def __init__(self,age):
self.age = age print(issubclass(Test4,Test3))
print(issubclass(Test3,Test4))

最新文章

  1. StackExchange.Redis 使用-配置
  2. 让javascript显原型!
  3. Memcache升级版:CouchBase的安装配置与使用说明
  4. react native get started run 模拟机报错解决
  5. OGLplus 0.33.0 发布,OpenGL 的 C 封装库
  6. 也谈http中get和post
  7. nodejs中间层现实
  8. 图论(对偶图):COGS 470. [NOI2010]海拔
  9. adb shell - device not found
  10. PT与PX,em(%)区别
  11. OC补充
  12. padding当高度用时出现的问题
  13. ReactJS入门基础
  14. [js高手之路]深入浅出webpack教程系列9-打包图片(file-loader)用法
  15. spring data jpa 学习笔记
  16. 2.第一个python 程序
  17. JDK版本更换,Eclipse中所有的项目报错
  18. Redo丢失的4种情况及处理方法
  19. boost asio 学习(三)post与dispatch
  20. 深入浅出MyBatis-快速入门

热门文章

  1. css多行文本溢出显示省略号(兼容ie)
  2. ajax加载引起瀑布流布局堆叠
  3. rem布局方案
  4. 用生动的案例一步步带你学会python多线程模块
  5. vue脚手架安装,新建项目,打包
  6. Codeforce612C
  7. 2018HDU多校五-G题 Glad You Game (线段树)
  8. 最全的防火墙(firewalld)
  9. mongodb验证
  10. 2.成产出现 max(vachar2)取值问题