# -*- coding:gb2312 -*-
class car:
# 属性
# 方法
def __str__():
print("哈哈哈哈哈哈啊哈")
def move():
print("车在移动。")
def Whistle():
print("车载鸣笛。")
BMW = car()
print(BMW)
Error message:
Google translated it and said that it takes 0 position parameters, but it gave 1
I don’t understand what this means.
The functions defined in
class
need to provide a positional parameter ofself
, because when the class is instantiated, the instance object will be passed in and then bound to the function, so the code should be adjusted to:For the relationship between
method
andfunction
, you can refer to my article: Python: The difference between functions and methods