+ 2

i need help

class User(): def __init__(self , user_name , user_lname , user_bday ,user_addres , user_age): self.user_name = user_name self.user_lname = user_lname self.user_bday = user_bday self.user_addres = user_addres self.user_age = user_age def describe_user(self): print("User name " + self.user_name) print("User last name " + self.user_lname) print("User bday " + self.user_bday) print("User addres " + self.user_addres) print("User age " + str(self.user_age)) def greet_user(self): print("Hello " + self.user_name) user = User("Micle " , "Jonson" ,"Dec 12" , "Grove str" , 20) user1 = User("Bob" , "Jeferson" ,"March 20" , "Cool str" , 18) user2 = User("Yan" , "Kallioma" , "March 20" ,"Very cool str" , 22) print(user.describe_user) print(user1.describe_user) print(user2.describe_user) print(user.greet_user) print(user1.greet_user) print(user2.greet_user) why output this ?: <bound method User.describe_user of <__main__.User object at 0x7f33712acf98>> <bound method User.describe_user of <__main__.User object at 0x7f33712acef0>> <bound method User.describe_user of <__main__.User object at 0x7f33712acfd0>> <bound method User.greet_user of <__main__.User object at 0x7f33712acf98>> <bound method User.greet_user of <__main__.User object at 0x7f33712acef0>> <bound method User.greet_user of <__main__.User object at 0x7f33712acfd0>>

7th Mar 2018, 4:31 PM
genios__
genios__ - avatar
1 Answer
+ 2
Because you print memory addresses of function objects. Correct way to call a function is like user.describe_user(). If you don't include parenthesis, then it will be the function object. And you don't need to use print when calling a function which return nothing. In your code, describe_user and greet_user function return nothing. So, correct way would be like this: user.describe_user() user.greet_user()
7th Mar 2018, 4:40 PM
Sylar