Python学习之函数与方法的区别

函数和方法严格意义上讲都是可执行的一个代码段,拥有输入和输出

在Python中函数为内置的,函数是已经封装的一些独立的功能,同时也满足自建的一些函数。

import keyword
print(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中的关键字,不能重新定义。

方法和函数类似,不过方法通过对象来调用。

猜你喜欢

转载自www.cnblogs.com/bohemiaCP/p/9955802.html
今日推荐