0

How do i PRINT any method i want from a class ?? Whenever i try it just gives me it's location in memory i believe.(

class Employee: def __init__(self, first, last): self.first = first self.last = last self.email = f"{self.first}.{self.last}@email.com" def fullname(self): return self.first, self.last def __str__(self): return f"{self.first},{self.last}" eric = Employee("eric", "larson") print(eric.fullname) print(eric.email)

22nd Aug 2023, 4:56 PM
Intermediate Depression
Intermediate Depression - avatar
4 Respostas
+ 5
print(eric.fullname())
22nd Aug 2023, 5:05 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
+ 2
Intermediate Depression When you call a function with parentheses, you are telling the interpreter that you want to execute the code inside that function. When you use the function name without parentheses, you are referring to the function itself as an object. This can be useful, for example, if you want to pass the function as an argument to another function or store it in a variable. if you call a function without parentheses, you won't execute the code inside that function. You're simply referring to the function object, which can be used later for calling.
22nd Aug 2023, 7:55 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
0
Alexey Kopyshev TYSM, i am very amazed at how simple the answer is wow.....can you please explain what is the difference? (Between calling it like a function and calling it normally how i did in my code!)
22nd Aug 2023, 7:04 PM
Intermediate Depression
Intermediate Depression - avatar
0
Alexey Kopyshev Again thank you so much you have no idea how much you have helped me, i really appreciate your help.
23rd Aug 2023, 1:06 AM
Intermediate Depression
Intermediate Depression - avatar