Navigation

The rules for when uses Python call by value or call by reference to
pass paramters to functions is used are the same as they are in Java. The
core built-in data types (int, long, float and string) are all immutable
data types and when they are passed to either a function or class methods,
call by value is used. When mutable objects are used with class methods,
call by reference is used.

The __init__(self,other_args) method is initialization code, not a
constructor – subtle point. A __new__() method may also be declared,
which is a constructor. You will not need the __new__() method for
this class.

Python features which are not loaded, by default can brought into a Python by
importing a module.

Module foo would be imported using a importfoo statement.
This loads the module and evaluates it’s code. Classes
and functions from the module are then called with the module name prefixed:
x=foo.bar().

If we just want to import the bar() function, we could use the
following syntax: fromfooimportbar. Now, we could call the
bar() as simply: x=bar().

Note

Upon importing a module, the code in the module is evaluated. This means
that classes and functions become available since Python knows about them
only after they are evaluated. But this also means that any global
statements get executed when they are imported.

In simple Python scripts, we often put the code at the global level.
This is fine, if the code will never be imported. A better, long term
strategy is to put most, or all of the code inside functions and classes
and add a statement such as the following at the end of the file:

if__name__=='__main__':main()

The above statements execute a function called main if the program is
run as a stand alone program, but not if it is imported. The global
name: __name__ is a built-in name, which is set to ‘__main__’ when
the file is executed directly by Python, but is the name of the module
when it is imported.