Python笔记4(内置函数)

一、内置函数

截止到python版本3.6.2,现在python一共为我们提供了68个内置函数。它们就是python提供给你直接可以拿来使用的所有函数。

 Built-in Functions  
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()  
delattr() hash() memoryview() set()  

 

 

 

 

 

 

上面就是内置函数的表,68个函数都在这儿了。这个表的顺序是按照首字母的排列顺序来的,把这些函数分成了6大类。 

目前学习用粉红色标注出来的这四大块——56个方法。还有12个方法讲完面向对象后再添加。

二、作用域相关 globals()   locals()

基于字典的形式获取局部变量和全局变量

globals()——获取全局变量的字典

locals()——获取执行本方法所在命名空间内的局部变量的字典

 1 #内置函数
 2 #globals() 把全局变量和值的关系放在字典中
 3 #locals() 把局部变量与值的关系放在字典中
 4 name1='Lucy'
 5 def func1():
 6     name2 = 'Lily'
 7     print(globals())
 8     print(locals())
 9 func1()
10 #>>>{'__name__': '__main__', '__doc__': '

', '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000001E474CEC2B0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:/Users/28163/PycharmProjects/python21期/day3/day3笔记.py', '__cached__': None, 'name1': 'Lucy', 'func1': <function func1 at 0x000001E474DC5F28>}
11 #>>>{'name2': 'Lily'}
示例

 三、其他

1、字符串类型代码的执行  eval()  exec()  compile()

2、输入输出  input()  print()

3、内存相关  hash()  id()

4、文件操作相关  open()

5、模块相关  __import__()

6、帮助  help()

7、调用相关  callable()

8、查看内存属性  dir()

 

原文地址:https://www.cnblogs.com/xingye-mdd/p/8977638.html