python看模块内函数 python怎么看模块方法( 二 )


class User(object):
def __init__(self,name):
self.name = name
def get_name(self):
return self.get_name
@property
def name(self):
return self_name
24.type() 函数返回对象的类型
25.list() 方法用于将元组转换为列表
b=(1,2,3,4,5,6)
list(b)
[1, 2, 3, 4, 5, 6]
26.range() 函数可创建一个整数列表,一般用在 for 循环中
range(10)
range(0, 10)
range(10,20)
range(10, 20)
27. getattr() 函数用于返回一个对象属性值
class w(object):
...s=5
...
a = w()
getattr(a,'s')
5
28. complex() 函数用于创建一个复数或者转化一个字符串或数为复数 。如果第一个参数为字符串,则不需要指定第二个参数
complex(1,2)
(1+2j)
complex(1)
(1+0j)
complex("1")
(1+0j)
29.max() 方法返回给定参数的最大值,参数可以为序列
b=(1,2,3,4,5,6)
max(b)
6
30. round() 方法返回浮点数x的四舍五入值
round(10.56)
11
round(10.45)
10
round(10.45,1)
10.4
round(10.56,1)
10.6
round(10.565,2)
10.56
31. delattr 函数用于删除属性
class Num(object):
...a=1
...b=2
...c=3.
.. print1 = Num()
print('a=',print1.a)
a= 1
print('b=',print1.b)
b= 2
print('c=',print1.c)
c= 3
delattr(Num,'b')
print('b=',print1.b)
Traceback (most recent call last):File "", line 1, inAttributeError: 'Num' object has no attribute 'b'
32. hash() 用于获取取一个对象(字符串或者数值等)的哈希值
hash(2)
2
hash("tom")
-1675102375494872622
33. set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集、差集、并集等 。
a= set("tom")
b = set("marrt")
a,b
({'t', 'm', 'o'}, {'m', 't', 'a', 'r'})
ab#交集
{'t', 'm'}
a|b#并集
{'t', 'm', 'r', 'o', 'a'}
a-b#差集
{'o'}
python内置函数python内置函数是什么?一起来看下吧:
python内置函数有:
abs:求数值的绝对值
abs(-2)2
pmod:返回两个数值的商和余数
pmod(5,2)(2,1)pmod(5.5,2)(2.0,1.5)
bool:根据传入的参数的逻辑值创建一个布尔值
bool() #未传入参数Falsebool(0) #数值0、空序列等值为FalseFalsebool(1)True
all:判断可迭代对象的每个元素是否都为True值
all([1,2]) #列表中每个元素逻辑值均为True,返回TrueTrueall(()) #空元组Trueall({}) #空字典True
help:返回对象的帮助信息
help(str)Help on class str in module builtins:class str(object)|str(object='') - str|str(bytes_or_buffer[, encoding[, errors]]) - str||Create a new string object from the given object. If encoding or|errors is specified, then the object must expose a data buffer|that will be decoded using the given encoding and error handler.|Otherwise, returns the result of object.__str__() (if defined)|or repr(object).|encoding defaults to sys.getdefaultencoding().|errors defaults to 'strict'.||Methods defined here:||__add__(self, value, /)Return self+value.
_import_:动态导入模块
index = __import__('index')index.sayHello()
locals:返回当前作用域内的局部变量和其值组成的字典
def f():print('before define a ')print(locals()) #作用域内无变量a = 1print('after define a')print(locals()) #作用域内有一个a变量 , 值为1f f()before define a{}after define a{'a': 1}
input:读取用户输入值
s = input('please input your name:')please input your name:Ains'Ain'
open:使用指定的模式和编码打开文件,返回文件读写对象
# t为文本读写,b为二进制读写a = open('test.txt','rt')a.read()'some text'a.close()

推荐阅读