Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
62 views

Chapter 2 - Python Overview

This chapter provides an overview of Python. It discusses Python programs and modules, namespaces, the garbage collector, and differences between Python 2 and Python 3. Python programs can be executed directly or imported as modules. Each module has its own namespace. The garbage collector automatically clears unused memory in Python. Python 2 is legacy while Python 3 is the current and future version, but this course will use Python 2.7.

Uploaded by

Dana Țirigan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Chapter 2 - Python Overview

This chapter provides an overview of Python. It discusses Python programs and modules, namespaces, the garbage collector, and differences between Python 2 and Python 3. Python programs can be executed directly or imported as modules. Each module has its own namespace. The garbage collector automatically clears unused memory in Python. Python 2 is legacy while Python 3 is the current and future version, but this course will use Python 2.7.

Uploaded by

Dana Țirigan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Chapter 2 – Python Overview

Chapter 2 – Python Overview

2.1. Python programs


2.2. Python namespaces
2.3. Garbage collector
2.4. Python 2 vs Python 3
2.1. Python programs

• Python programs and modules are written as text files having


.py extensions
• Python modules and programs are differentiated only by the
way they are called:
– .py files executed directly are programs (or scripts)
Ex: $ python some_program.py
– .py files referenced via import statement are modules
Ex: some_program.py may contain:
import some_module
$ python some_program.py
– the same .py file can be a program or a module (for regression
tests)
• when module is executed as a program, the regression tests are
executed
• when module is imported, test functionality are not executed
2.2. Python namespaces

• each Python module has its own discrete namespace


– two different modules may both define a function ( users of the
modules must prefix it with the module name)
• namespaces are created at different moments and have
different lifetimes
– The namespace containing the built-in names is created when the
Python interpreter starts up, and is never deleted.
– The global namespace for a module is created when the module
definition is read in
• the local namespace for a function is created when the
function is called, and deleted when the function returns

• https://docs.python.org/2/tutorial/classes.html#python-scopes-
and-namespaces
2.3. Garbage collector

• In Python, all objects are pointers (in the behind C/C++)


• Python is a programming language which has a garbage
collector
• Similar with Java
• No need for clearing the objects (except for those
applications which require this)
2.4. Python 2 vs Python 3

• Python 2.x is legacy, Python 3.x is the present and future of


the language (released in 2008)
• The final 2.x version 2.7 release came out in mid-2010, with a
statement of extended support for this end-of-life release.
• The 2.x branch will see no new major releases after that. 3.x
is under active development and has already seen over five
years of stable releases, including version 3.3 in 2012 and 3.4
in 2014. This means that all recent standard library
improvements, for example, are only available by default in
Python 3.x.
• This course will be on Python 2.7
• More on https://wiki.python.org/moin/Python2orPython3

You might also like