1
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

4

1 回答 1

0

来自: 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"
于 2019-04-22T14:49:43.340 回答