Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

A Python Class Constructor

class Person:
  def __init__(self, fname, lname):
    self.fname = fname
    self.lname = lname

p1 = Person("John", "Smith")

print(p1.fname)
print(p1.lname)
Comment

PREVIOUS NEXT
Code Example
Python :: how to end an infinite loop in specific time python 
Python :: epoch to gmt python 
Python :: pip install mod_wsgi error 
Python :: Creating and writing to a new file 
Python :: python ctypes maximize window 
Python :: change the side of the axis plt python 
Python :: dataframe pandas empty 
Python :: transformers bert 
Python :: len function in python 
Python :: how to change the disabled color in tkinter 
Python :: Example Layout using grid() in tkinter 
Python :: python regex search a words among list 
Python :: List Delete a Element 
Python :: python list replace nan with 0 
Python :: how to make a dice program in python 
Python :: selenium python get element by type 
Python :: python pathlib 
Python :: cv2 check if image is grayscale 
Python :: divide every element in numpy array 
Python :: combine list of dicts 
Python :: python bufferedreader 
Python :: python get screen size raspberry pi 
Python :: def python 
Python :: python round without math 
Python :: bar plot 
Python :: activate python virtual environment 
Python :: find all unique substring permutations of a string of a specific length python 
Python :: python code to demonstrate inheritance 
Python :: merge two netcdf files using xarray 
Python :: appending to a list python 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =