四时宝库

程序员的知识宝库

python变量命名规则

1、变量的命名规则

在Python中使用变量,和其他编程语言一样也需要遵守一定的规则。违反这些规则将引发错误,而这些规则的存在旨在让你编写的代码容易阅读和理解。请牢记下述有关的变量规则。

  • 变量名只能包含字母、数字和下划线。变量名可以字母或下火线开头,但不可以是数字。可以将变量名命名为user_1或_user1,但不可以命名为1_user
  • 变量名不可包含空格,否则会引发错误。
  • 不要将Python关键字和内置函数名用作变量名,参见Python语言关键词
  • 变量应简短富有描述性。如,student,user_name,worker等
  • 慎用小写字母l和大写字母O,容易和类似的数字混淆。i的大写字母I和L的小写l还有数字1容易混淆,数字0和大写字母O。



2、Python语言关键词

False      class      finally    
is         return			None       
continue   for        lambda     
try				 True       def        
from       nonlocal   while
and        del        global     
not        with       as         
elif       if         or         
yield      assert     else       
import     pass       break      
except     in         raise


3、Python内置函数名称

注:内置函数以python3.13为参照

A

abs()

aiter()

all()

anext()

any()

ascii()

B

bin()

bool()

breakpoint()

bytearray()

bytes()

C

callable()

chr()

classmethod()

compile()

complex()

D

delattr()

dict()

dir()

divmod()

E

enumerate()

eval()

exec()

F

filter()

float()

format()

frozenset()

G

getattr()

globals()

H

hasattr()

hash()

help()

hex()

I

id()

input()

int()

isinstance()

issubclass()

iter()

L

len()

list()

locals()

M

map()

max()

memoryview()

min()

N

next()

O

object()

oct()

open()

ord()

P

pow()

print()

property()

R

range()

repr()

reversed()

round()

S

set()

setattr()

slice()

sorted()

staticmethod()

str()

sum()

super()

T

tuple()

type()

V

vars()

Z

zip()

_

__import__()

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接