Python入门-内置对象函数
2021/8/18 12:07:27
本文主要是介绍Python入门-内置对象函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.callable()
查看函数知否可调用,可调用返回True,不可用返回False
print("input函数:", callable(input)) #input函数: True
2.eval()
print(eval("3+3")) # 6 num = 10 s = "加法计算:{}" var = dict(num =num, info = s) res = eval("info.format(num *2)", var) res # '加法计算:20' l = "[1,2,3]" t = "(1,2,3)" d = "{1:'one',2:'two',3:'three'}" res = eval(l) res2 = eval(t) res3 = eval(d) print(res, res2, res3) print(type(res,),type(res2), type(res3)) """ [1, 2, 3] (1, 2, 3) {1: 'one', 2: 'two', 3: 'three'} <class 'list'> <class 'tuple'> <class 'dict'> """
3.exec()
num =10 exec("num += 11") num # 21 s = "for i in range(10):"\ "print(i,end= ',')" res = exec(s) print() print(res) """ 0,1,2,3,4,5,6,7,8,9, None """
4.compie()
s = "11 + 22 " code = compile(s, " ","eval") res = eval(code) res # 33 s = "data = input('请输入:')" code = compile(s,"", "single") exec(code) print("输入数据为:", data) """ 请输入: 99 输入数据为: 99 """ s = [] data = "for i in range(2):s.append(input('请输入:'))" code = compile(data, "", "exec") exec(code) exec("print('经常访问的地址:',s)") """ 请输入: baidu 请输入: google 经常访问的地址: ['baidu', 'google'] """
这篇关于Python入门-内置对象函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享