1. abs() 取绝对值函数
1 #!/usr/bin/env python 2 # _*_ coding: UTF-8 _*_ 3 # Author:taoke 4 i = 100 5 print(abs(i)) 6 i = -100 7 print(abs(i))
2.dict() 创建字典
1 print(dict({"a":1, "b":2, "c":3}))
3.help() 帮助函数
4.min() 返回最小项iterable或最小的两个或两个以上的参数。
1 print(min([1,2,34,5,6,7,0,100,-2]))
运行结果:-2
5.setattr() 给对象相应的属性赋值
setattr(x, ‘foobar‘, 123)
等同于x.foobar = 123
6.all() 全部为True返回True,否者返回Flase
1 print(all([1,23,45,3,-1])) 2 print(all([1,23,45,3,0,-1]))
运行结果:
True
False
7.ascii() 把一个内存的对象变为可打印的字符串形式
8.bin() 把一个整形转换成二进制字符串
1 print(bin(1)) 2 print(bin(2)) 3 print(bin(3)) 4 print(bin(4)) 5 print(bin(5)) 6 print(bin(255))
运行结果:
0b1
0b10
0b11
0b100
0b101
0b11111111
9.dir()函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。
1 print(dir([1,2,3,4,5]))
运行结果:
[‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__iadd__‘, ‘__imul__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__reversed__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘append‘, ‘clear‘, ‘copy‘, ‘count‘, ‘extend‘, ‘index‘, ‘insert‘, ‘pop‘, ‘remove‘, ‘reverse‘, ‘sort‘]
时间: 2024-12-29 06:46:31