🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।

Find the output of the following Python programs.

class Acc: 
	def __init__(self, id): 
		self.id = id
		id = 555

acc = Acc(111) 
print (acc.id) 
A
111
B
555
C
666
D
error in code
Explanation
  • The __init__ method takes a parameter id, and assigns that value to the instance attribute self.id.
  • The line id = 555 modifies the local id variable in the constructor, but does not affect the instance variable self.id.
  • When you print acc.id, it will print the value that was passed into the constructor, which is 111.

Output:

 
111 

Explanation:

  • The id inside the __init__ method is a local variable. Changing it doesn't affect the instance variable self.id.
  • So, the value of self.id remains as 111 even though id = 555 is set within the constructor.self.id = id इंस्टेंस वेरिएबल को असाइन करता है। अगली लाइन id = 555 केवल एक लोकल वेरिएबल को बदलती है, क्लास के
  • self.id को नहीं। इसलिए acc.id का मान 111 ही रहेगा।

Correct Answer: A) 111

Latest Updates