Post

New Technology
New Technology@pythonclcoding·
What is the output of following Python code? class People(): def __init__(self, name): self.name = name def namePrint(self): print(self.name) person1 = People("Sally") person2 = People("Louise") person1.namePrint()
English
4
2
17
21.6K
Anslem
Anslem@anslemeriyo·
__init__ method is the constructor method that initializes the object. It takes a parameter name and assigns it to the instance variable self.name. namePrint method: This method prints the value of the name instance variable. We create two instances of the People class: person1 with the name "Sally" and person2 with the name "Louise". We call the namePrint method on person1, which prints the value of the name instance variable of person1, resulting in the output "Sally".
English
0
0
0
507
Earnest Codes
Earnest Codes@Earnesto037·
@pythonclcoding Answer is Sally. Let's break down the code step by step to understand why the output is "Sally": A mini Thread🧵 1. Class Definition: class People(): Here, we define a class named `People`. Classes in Python are like blueprints for creating objects.
Earnest Codes tweet media
English
0
0
0
313
PythonicJourney
PythonicJourney@pythonicjourney·
@pythonclcoding Sally. `__init__` method initializes the name attribute of the People class. Instances person1 and person2 of the People class are created with names "Sally" and "Louise" respectively. `namePrint` method is called for person1 which prints the name 'Sally' to the console.
English
0
0
0
5
Paylaş