0
Q:

python class constructor

class Human:
	def __init__(self, name):
      self.name = name

h1 = Human("Bob")
print(h1.name) # prints Bob, the name passed from constructor
4
class GeekforGeeks: 
    geek = "" 
  
    # default constructor 
    def __init__(self): 
        self.geek = "GeekforGeeks"
  
    # a method for printing data members 
    def print_Geek(self): 
        print(self.geek) 
  
  
# creating object of the class 
obj = GeekforGeeks() 
  
# calling the instance method using the object obj 
obj.print_Geek() 
5
def __init__(self):
    # body of the constructor
1

New to Communities?

Join the community