【发布时间】:2023-03-15 16:46:02
【问题描述】:
class Person:
def __init__(self, name):
"""Make a new person with the given name."""
self.myname = name
def introduction(myname):
"""Returns an introduction for this person."""
return "Hi, my name is {}.".format(myname)
# Use the class to introduce Mark and Steve
mark = Person("Mark")
steve = Person("Steve")
print(mark.introduction())
print(steve.introduction())
它假设产生 “你好,我叫马克。”或“嗨,我叫史蒂夫。”
但它会产生 “嗨,我的名字未定义。”
【问题讨论】:
-
为什么一定要讨厌缩进?
-
@mrdomoboto 真的不需要老兄。只需让他缩进他的代码即可。
-
对不起。我不明白。缩进哪一个?
-
@Mr.Python 当您要求其他人用依赖空格作为范围的语言来帮助您解决问题时,这是基本的礼貌。
-
我完全同意。不过没必要这么说
标签: python class oop object methods