I Spy Code - Python

Initializing Object Variables

Here is a python example that shows how to initialize an object with variables:

Source: (example.py)

class Person(object):
   def __init__(self,name,age):
      self.name = name
      self.age = age
 
p = Person("Tom",18)
 
print(p.name)
print(p.age)
 

Output:

$ python example.py
Tom
18


Related Examples

Call Methods Dynamically
Docstring
Initializing Object Variables
Method Arguments
Subclass Inherits Method
Test For Null Object
hqdwppls.php

7