python中关键字,函数,方法的理解

关键字:
关键字是python内置的,是具有特殊意义的标识符

import keyword
print("python中关键字的个数是:%d"%len(keyword.kwlist))
print(keyword.kwlist)
# python中关键字的个数是:33
# ['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内置了许多函数,同时可以自建函数来使用。

方法

  方法和函数类似,同样封装了独立的功能,但是方法是需要通过对象来调用的,表示针对这个对象要做的操作,使用时采用点方法。
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_37615098/article/details/82289084