Q:

Can we take any name in place of self in python?

0

Can we take any name in place of self?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 male
color is white
Gender is Woman
color is Black

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Interview Questions and Answers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is a function in Python Programming?... >>
<< What is pep 8 in Python?...