Why self is used in methods or init method in python

0 votes

Why self is used in methods or init() method in python? Can someone explain the above query?

Oct 6, 2020 in Python by anonymous
• 8,880 points
47 views

1 answer to this question.

0 votes

its a constructor like in C++. In c++ compiler will auto-detect the respective object of constructor. But in python, the self is nothing but the class instance, the python compiler will need the self (nothing but instance) to know for which instance the constructor is called, so self is passed to init(). Self is an instance of a class and we can access the instance variable of a class.

answered Oct 6, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How does Python know whether a variable in the class is a method or a variable?

In python objects/variables are wrapped into methods ...READ MORE

answered Sep 18, 2018 in Python by aryya
• 7,420 points
195 views
0 votes
1 answer

.join() method is used for what purpose in Python?

join() method is used to concatenate or ...READ MORE

answered May 14, 2019 in Python by Taj
• 1,080 points
265 views
0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 58,100 points
2,051 views
0 votes
1 answer

How random.seed(): is used in python?

Pseudo-random number generators work by performing some ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 58,100 points
116 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,836 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,417 views
+1 vote
7 answers
0 votes
3 answers

Python exit commands - why so many and when should each be used?

The functions* quit(), exit(), and sys.exit() function in the same way: ...READ MORE

answered Dec 13, 2020 in Python by Gitika
• 65,870 points
53,106 views