There are 2 current versions of Python: version 2 and version 3. Version 3 is not fully compatible with version 2, so if you are starting with Python, I think is is wise to go with version 3, but be aware that most existing applications and Open Source projects use version 2.
If you are using a GNU based system, chances are that Python is already installed in you system. Otherwise, it will be available in your distribution repositories. As far as I know, Python is also available on the Mac via the terminal. On widows, you will have to download a Python distribution from https://python.org/download. On this page you will also find links for downloading Python for Linux, MacOS, etc.
If you go to this site, you will notice that they mention alternative implementations of Python. The implementation I will be talking about here is the one done in C.
To install Python, you also can download the source code and compile it yourself.
Have a look at this link
Python is intended to be a highly readable language. It is designed to have an uncluttered visual layout, frequently using English keywords where other languages use punctuation. Python requires less boilerplate than traditional manifestly typed structured languages such as C or Pascal, and has a smaller number of syntactic exceptions and special cases than either of these.
The simplicity of Python is demonstrated by its version of the classic "Hello world" program:
print("Hello world")
Indentation
Python uses whitespace indentation, rather than curly braces or keywords, to delimit blocks; a feature also termed the off-side rule. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.
Statements and control flow
Python's statements include (among others):
The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if).
The for statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
The while statement, which executes a block of code as long as its condition is true.
The class statement, which executes a block of code and attaches its local namespace to a class, for use in object-oriented programming.
The def statement, which defines a function or method.
The import statement, which is used to import modules whose functions or variables can be used in the current program.
Each statement has its own semantics: for example, the def statement does not execute its block immediately, unlike most other statements.
Expressions
Python expressions are similar to languages such as C and Java.
In Python, == compares by value, in contrast to Java, where it compares by reference. (Value comparisons in Java use the equals() method.) Python's is operator may be used to compare object identities (comparison by reference). Comparisons may be chained, for example a <= b <= c.
Python uses the words and, or, not for its boolean operators rather than the symbolic &&, ||, ! used in Java and C.
Conditional expressions in Python are written as x if c else y (different in order of operands from the ?: operator common to many other languages).
Methods
Methods on objects are functions attached to the object's class; the syntax instance.method(argument) is, for normal methods and functions, syntactic sugar for Class.method(instance, argument). Python methods have an explicit self parameter to access instance data, in contrast to the implicit self in some other object-oriented programming languages (for example, Java, C++ or Ruby).
Typing
Python uses duck typing and has typed objects but untyped variable names. Type constraints are not checked at compile time; rather, operations on an object may fail, signifying that the given object is not of a suitable type. Despite being dynamically typed, Python is strongly typed, forbidding operations that are not well-defined (for example, adding a number to a string) rather than silently attempting to make sense of them.
Python allows programmers to define their own types using classes, which are most often used for object-oriented programming. New instances of classes are constructed by calling the class (for example, SpamClass() or EggsClass()), and the classes themselves are instances of the metaclass type (itself an instance of itself), allowing metaprogramming and reflection.
The section 3 of the python tutorial (An informal introduction to Python) gives a very good overview of the use of the interactive interpreter.
Of course, if you are going to write long programs, you will want to save them to files which can then be passed to the interpreter for execution.
Python has a very rich standard library, that is a set of modules which are part of the standard Python installation and which provide many interesting functions which in many other languages are only provided by 3rd party libraries :
The main reference is the Python documentation page at https://docs.python.org/ . There you will find a very useful tutorial (this is the place to start), the standard library reference, and many other interesting information.
Unless otherwise stated, our shows are released under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
The HPR Website Design is released to the Public Domain.