当前位置:首页 » 编程语言 » python的内置函数

python的内置函数

发布时间: 2023-11-02 15:49:54

‘壹’ python里面有哪些自带函数

python系统提供了下面常用的函数:
1. 数学库模块(math)提供了很多数学运算函数;
2.复数模块(cmath)提供了用于复数运算的函数;
3.随机数模块(random)提供了用来生成随机数的函数;
4.时间(time)和日历(calendar)模块提供了能处理日期和时间的函数。
注意:在调用系统函数之前,先要使用import 语句导入 相应的模块
该语句将模块中定义的函数代码复制到自己的程 序中,然后就可以访问模块中的任何函数,其方 法是在函数名前面加上“模块名.”。
希望能帮到你。

‘贰’ python内置函数

python内置函数是什么?一起来看下吧:

python内置函数有:

abs:求数值的绝对值
>>>abs(-2) 2
pmod:返回两个数值的商和余数

>>>pmod(5,2) (2,1) >>pmod(5.5,2) (2.0,1.5)
bool:根据传入的参数的逻辑值创建一个布尔值

>>>bool() #未传入参数 False >>>bool(0) #数值0、空序列等值为False False >>>bool(1) True
all:判断可迭代对象的每个元素是否都为True值
>>>all([1,2]) #列表中每个元素逻辑值均为True,返回True True >>> all(()) #空元组 True >>> all({}) #空字典 True
help:返回对象的帮助信息
>>> help(str)  Help on class str in mole 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 = 1     print('after define a')     print(locals()) #作用域内有一个a变量,值为1 >>> f>>> f() before define a  {}  after 磨枝define a {'a': 1}
input:读取用户输入值
>>瞎肆敏> s = input('please input your name:') please input your name:Ain >>> s 'Ain'
open:使用指定的模式和编码打开文件,返回文件读写对象
# t为文本读写,b为二进制读写 >>> a = open('test.txt','rt') >>> a.read() 'some text' >>> a.close()
eval:执行动态表达式求值
>>> eval('1+2+3+4') 10

除了上述举例的函数之外,内置函数按分类还可分为:

1、数学运算(7个)

2、类型转换(24个)

3、序列操作(8个)

4、对象操作(7个)

5、反射操作(8个)

6、变量操作(2个)

7、交互操作(2个)

8、文件操作(1个)

9、编译操作(4个)

10、装饰器(3个)

‘叁’ python语言中可以调用的函数有哪些

Python语言中有碰锋很多内置函数和标准库函数可以直接调用,同时还可以自定义函数和调用其他模块中的函数。以下是一些常用的Python内置函数和标准库函数:

  1. 数学函数:abs(), pow(), round(), max(), min(), math库中的sin(), cos(), tan(), pi等函数。
  2. 字符串函迟腔数:len(), str(), int(), float(), ord(), chr(), upper(), lower(), replace(), split()等函数。
  3. 列表函数:append(), extend(), insert(), remove(), pop(), sort(), reverse()等函数。
  4. 文件操作函数:open(), read(), write(), close()等函数。
  5. 时间和日期函数:time(), sleep(), strftime()等函数。
  6. 正则表达式函数:re.compile(), re.search(), re.match(), re.sub()等函数。
  7. 网络编程函数:socket库中笑旦晌的socket(), bind(), listen(), accept()等函数。
热点内容
androidsaxxml解析xml 发布:2025-07-18 10:57:58 浏览:385
ios透明文件夹插件 发布:2025-07-18 10:51:36 浏览:841
大众蔚揽gte如何连接安卓 发布:2025-07-18 10:45:57 浏览:876
服务器驱动怎么安装 发布:2025-07-18 10:35:15 浏览:817
路由器密码忘了怎么改 发布:2025-07-18 10:32:13 浏览:450
android管家 发布:2025-07-18 10:25:02 浏览:70
网站访问地区 发布:2025-07-18 10:24:55 浏览:260
缓存传文件 发布:2025-07-18 10:18:33 浏览:155
生信差异分析的脚本 发布:2025-07-18 10:14:50 浏览:598
微信打开网页继续访问 发布:2025-07-18 10:09:50 浏览:50