• Your Cart is Empty
  • Cart
  • Log In

Python (programming language)

Python overview

Python is an easy and powerful object-oriented programming language. It was originally created back in the 1980's, but saw it's first public release in 1991. After the release of Python 1.0 in 1994, it quickly became one of the preferred programming language for the creation of web applications in the Internet, alongside with Perl and PHP. It's creator, Guido van Rossum has played a major part in the Python development from it's first release and has a central role in deciding the direction of the Python development.

Python is often used as a scripting language for web applications in combination with the "mod python" module for the Apache web server. Python's easiness of use and ability to integrate with different SDKs allows the creation of many different programs for Windows, Linux, Маc ОS and other operational systems.

Python syntax

Among the most important characteristics of Python is the use of elegant syntax, which allows the users to read program code easily and which makes it suitable for prototype development and different ad-hoc programming tasks. Python comes with an inbuilt development environment called IDLE and offers a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files. In interactive mode Python can easily test even small portions of code.

Python modules

A great Python feature, which makes it a preferred choice for complex applications is it's ability to split your program into modules, which can later be used with other Python-based applications. Python also offers a larger collection of modules, which can be used. These modules vary from simple modules, which can be used as examples to start understanding Python to modules, which can provide interfaces to GUI (graphical user interfaces), like Tk.

Python variables

As a difference to PHP and Perl, variables in Python are not designated with a sygil "$" in front of them. Instead, following Python's philosophy for a more simple and elegant syntax, variables are announced with a simple text.

Variables in Python:

>>> width = 20
>>> height = 5*9

You can also assign one value to several variables at a time:

>>> x = y = z = 0  # Zero x, y and z
>>> x
0
>>> y
0
>>> z
0

Python Strings

Like the rest of the programming languages, Python can also operate with strings. They can be enclosed with both single or double quotes:

Simple strings in Python:

>>> 'test string'
'test string'
>>> 'doesn\'t'
"doesn't"
>>> "doesn't"
"doesn't"
>>> '"Yes," he said.'
'"Yes," he said.'
>>> "\"Yes,\" he said."
'"Yes," he said.'
>>> '"Isn\'t," she said.'
'"Isn\'t," she said.'

Strings can also be of several lines. You can span them using a backslash (\) and the \n escape character. A simple use of the backslash will be ignore and the string will not be spanned.

Python strings with multiple lines:

string = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
significant."
print string

The result will be:

This is a rather long string containing
several lines of text just as you would do in C.
Note that whitespace at the beginning of the line is significant.

In Python, you can also create "raw" string. They are strings, announces with a "r" before the quotes. With a "raw" string, the new line escape character "\n" and the backslash are considered a part of the string and not escape characters.

Raw Python strings

hello = r"This is a rather long string containing\n\
several lines of text much as you would do in C."

print hello

The above example will print:

This is a rather long string containing\n\
several lines of text much as you would do in C.

In Python, strings can also be glued together using the "+" symbol.

Merging strings in Python:

word = 'Help' + 'A'
print word

Will output:

'HelpA'

Two literal strings next to each other are automatically glued together:

word = 'Help' 'A'
print word

will return the same result.

Simple Python string printing examples:

#!/usr/bin/python
print "Hello world"
x = "Hello World"
print "The value of x is", x
# You can use either single or double quotes
# to enclose strings
print 'Also, the value of x is', x
print "Multiple lines: The value\n of x\n is", x

Python with NTC Hosting

To give our clients maximum freedom, we, at NTC Hosting, offer a Python-optimized web hosting service. All our users can run their own .py script quickly and easily. To do so, the following conditions have to be met:

  1. the python script must have permissions set to 755 and point to the following path: "#!/usr/bin/python"
  2. an .htaccess file must be created in the folder where the .py file is located with the following content: AddHandler cgi-script .py

Now you can enjoy working with your script inside your Python-enabled web hosting account.