Reputation: 3
Sorry to bother you guys with something like this, but new at this. Having a horrible time getting Classes to produce any output. Tried this in 3 IDE's and it comes up with no output. It could be I'm not including a library or my IDE's aren't set up right. Here's my simple program.
class Hello:
def printHello(self):
print ("hello")
x = Hello()
x.printHello()
Upvotes: 0
Views: 32
Reputation: 3177
A proper indentation in Python is mandatory in order to define blocks of code.
In your case you should have
class Hello: #line 1
def printHello(self): #line 2
print ("hello") #line 3
#line 4
x = Hello() #line 5
x.printHello() #line 6
with no spaces before x
in lines 5 and 6 and print()
on line 3 should be indented as well because it is part of the printHello()
function (just like the def
is part of class Hello
).
Upvotes: 1