Introduction to Python

Language description Python is a scripting language. It was designed as a glue language to execute operating system commands and call C++ scripts. It has evolved into something more that that. Now Python is used as a general-purpose multi-paradigm computer langauge. It can be used to create console applications, services…

Python: decisions

Making decisions The most common and maybe the most important statement you need to learn is the decision statement. This is represented in Python using the if  keyword followed by a conditional expression then followed by “:” like in example below: # —————————————— # program example for decision statement #…

Python: repetition

Description: Repetition is a statement or several statements that can be executed once or multiple times. The number of times is limited by a condition. Sometimes the repetition is forever and this is called infinite loop. There are 2 kind of repetition statements in Python: “while” and “for”. The “while”statement…

Python: data types

Type Inference In Python we do not declare data types for any of the variables. Python is a dynamic language and is automatically determine the data type using type inference. When we assign a value to an identifier this become a variable. The type of the variable is determined by…

Python: function

Define a function Python is an imperative language. In Python you can define procedures and functions using the same syntax for both. There is only one keyword: “def”. A function can calculate and return one or more results, while a procedure do not return anything. A procedure and a function…

Python: namespaces

Define namespace One of most fundamental concept a Python developer must understend is the namespace.  A namespace is a composite word from “name” and “space”. It represents a memory structure that hold several names. A namespace is defined by a “scope”. A scope is a region of program that is…

Python: function attributes

Creating Attributes In Python a function is an object. Any object can have attributes that can be created using a dot operator. Function attributes are attached to the function as static variables. This is another alternative to global variables and it can be used to create encapsulated functions that behave…

Python: switch simulation

Why simulation? Switch statement do not exist in Python.  However we can simulate a switch statement using different techniques. In the next example we create a function switch. This is a fake statement to simulate the switch. We use this program as an example. Read and try to understand the…