Can we take any name in place of self?
Answer :
Yes, we can. But it is advisable to use self because it increases the readability of code.
class human(): # init method or constructor def __init__(aticleworld, gender, color): aticleworld.gender = gender aticleworld.color = color def show(aticleworld): print("Gender is", aticleworld.gender ) print("color is", aticleworld.color ) amlendra = human("male", "white") pooja = human("Woman", "Black") amlendra.show() pooja.show()
Output:
Gender is malecolor is whiteGender is Womancolor is Black
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Answer :
Yes, we can. But it is advisable to use self because it increases the readability of code.
Output:
Gender is male
need an explanation for this answer? contact us directly to get an explanation for this answercolor is white
Gender is Woman
color is Black