0

SoloLearn's lesson misunderstanding

Code: class GameObject: class_name = "" desc = "" objects = {} def __init__(self, name): self.name = name GameObject.objects[self.class_name] = self def get_desc(self): return self.class_name + "\n" + self.desc class Goblin(GameObject): class_name = "goblin" desc = "A foul creature" goblin = Goblin("Gobbly") def examine(noun): if noun in GameObject.objects: return GameObject.objects[noun].get_desc() else: return "There is no {} here.".format(noun) Question: I don't understand why first line with "GameObject.objects..." in this code was written without any tabs? If it's in the definition of class GameObject it should be written with one tab before the line code, but it was written as something after the class definition. It will be maybe okay, but after that is "def get_desc" with one tab, so get_desc is in class.

21st Aug 2018, 10:05 AM
Ilyich
2 ответов
0
Tabs and spaces are not required for code to run. You often see this with websites that they'll have .min versions of files that take out all spacing to make the file load faster. Tabs and spaces are simply used to make the code more readable to humans.
23rd Aug 2018, 1:17 PM
George Raymond
George Raymond - avatar
0
George Raymond how programm , for example, understand where functions are ended without tabs and spaces? Or I don't understand something
23rd Aug 2018, 6:00 PM
Ilyich