首页 > 编程语言 > 详细

Python变量、关键字和内置函数

时间:2021-08-30 12:08:58      阅读:18      评论:0      收藏:0      [点我收藏+]
  1. Python 包含一系列关键字和内置函数,一般不建议使用它们作为变量名:
    如果开发者尝试使用关键字作为变量名,Python 解释器会报错。
    如果开发者使用内置函数的名字作为变量名,Python 解释器倒不会报错,只是该内置函数就被这个变量覆盖了,该内置函数就不能使用了。
# Python关键字
# 共 33 个关键字,除 True、False 和 None 外,其他关键字均为小写形式。
>>> import keyword
>>> keyword.kwlist
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘nonlocal‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]

不要使用内置函数的名字作为标识符使用(例如变量名、函数名、类名、模板名、对象名等)
Python 3.x内置函数
abs() delattr() hash() memoryview() set()
all() dict() help() min() setattr()
any() dir() hex() next() slicea()
ascii() divmod() id() object() sorted()
bin() enumerate() input() oct() staticmethod()
bool() eval() int() open() str()
breakpoint() 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()

Python变量、关键字和内置函数

原文:https://www.cnblogs.com/yatya/p/15195665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!