python存储函数 python如何存储数据

自定义函数可以独立存放于python文件中,通过什么导入到主自定义函数可以独立存放于python文件中,通过模块导入 。自定义模块采用import语句来进行引入,其操作步骤是先导入模块,再调用模块中包含的函数,可将自定义模块放入当前目录,便于解释器路径搜索 。
python中函数包括1. print()函数:打印字符串
2. raw_input()函数:从用户键盘捕获字符
【python存储函数 python如何存储数据】3. len()函数:计算字符长度
4. format(12.3654python存储函数 , '6.2f'/'0.3%')函数:实现格式化输出
5. type()函数:查询对象python存储函数的类型
6. int()函数、float()函数、str()函数等:类型的转化函数
7. id()函数:获取对象的内存地址
8. help()函数:Python的帮助函数
9. s.islower()函数:判断字符小写
10. s.sppace()函数:判断是否为空格
11. str.replace()函数:替换字符
12. import()函数:引进库
13. math.sin()函数:sin()函数
14. math.pow()函数:计算次方函数
15. 3**4: 3的4次方
16. pow(3,4)函数:3的4次方
17. os.getcwd()函数:获取当前工作目录
18. listdir()函数:显示当前目录下的文件
19. socket.gethostbyname()函数:获得某主机的IP地址
20. urllib.urlopen(url).read():打开网络内容并存储
21. open().write()函数:写入文件
22. webbrowser.open_new_tab()函数:新建标签并使用浏览器打开指定的网页
23. def function_name(parameters):自定义函数
24. time.sleep()函数:停止一段时间
25. random.randint()函数:产生随机数
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变量python存储函数,值为1f f()before define a{}after define a{'a': 1}
input:读取用户输入值
s = input('please input your name:')please input your name:Ains'Ain'
open:使用指定的模式和编码打开文件python存储函数,返回文件读写对象
# 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个)

推荐阅读