class student(object):
def __init__(self, grade, clas):
self.grade=grade
self.clas=clas
def __str__(self):
return "test"
mark=student("f","freshman")
print(mark)
这是结果 < main .student object at 0xb33eb2d0>
在 android 上通过 termux 学习 python
来自: Python_syntax_and_semantics#Indentation
Python 使用空格来分隔控制流块(遵循越位规则)。Python 借鉴了它的前身 ABC 的这一特性:它使用缩进来指示块的运行,而不是标点符号或关键字。
所以你的代码应该是:
class student(object):
def __init__(self, grade, clas):
self.grade=grade
self.clas=clas
def __str__(self):
return "test"