🚀 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)
B)
C)
D)

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.
Latest Updates