I already the pass the 3 arguments but show there are 2 arguments are missing | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

I already the pass the 3 arguments but show there are 2 arguments are missing

class stu: def __init__(s,name,city): s.name = name s.city = city def show(s,name,city): print("1",s.name) print("2",s.city) p = stu("yakin","newyork") p.show()

6th Apr 2022, 6:36 AM
Amala Yakin
4 Réponses
+ 1
def show( s ): You don't need <name> or <city>, you will get those values from properties of object <s>
6th Apr 2022, 6:41 AM
Ipang
+ 1
You don't need to pass them when you want to display them. See the object <s> refers to a `stu` instance, and it is expected to have properties named <name> and <city>. Which part is confusing you BTW?
6th Apr 2022, 6:46 AM
Ipang
+ 1
s already got name and city as properties because of what you declared in __init__. Just pass s as an argument for show() and use s.name and s.city in your print() function. https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_classes.asp
6th Apr 2022, 7:10 AM
Orisa
Orisa - avatar
0
Then how pass your value to given method
6th Apr 2022, 6:42 AM
Amala Yakin