News

Ten essential Python tips for beginners

Today, Python is one of the most popular programming languages in the open source space. It's a vast language and there are many gems to discover - here are ten tips for new users to get the ball rolling…

Python is a programming language that lets you work more quickly and integrate your systems more effectively and is one of the most popular programming languages in the open source space. Look around and you will find it running everywhere, from various configuration tools to XML parsing. We’ve compiled ten essential Python tips especially for the new user, so without further ado, let’s get started…

1. Running Python scripts
On most of the UNIX systems, you can run Python scripts from the command line like so:

$ python mypyprog.py

2. Running Python programs from Python interpreter
The Python interactive interpreter makes it easy to try your first steps in programming and using all Python commands. You just issue each command at the command prompt, one by one, and the answer is immediate.
Python interpreter can be started by issuing the command:

$ python
kunal@ubuntu:~$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> <type commands here>

In this article, all the code starting at the  >>> symbol is meant to be given at the
Python prompt. It is also important to remember that Python takes tabs very seriously – so if you are receiving any error that mentions tabs, correct the tab spacing.

3. Dynamic typing
In Java, C++, and other statically typed languages, you must specify the data type of the function return value and each function argument. On the other hand, Python is a dynamically typed language. In Python you never have to explicitly specify the data type of anything. Based on what value you assign, Python will keep track of the data type internally.

4. Python statements
Python uses carriage returns to separate statements, and a colon and indentation to separate code blocks. Most of the compiled programming languages, such as C and C++, use semicolons to separate statements and curly brackets to separate code blocks.

5.  == and = operators
Python uses ‘==’ for comparison and ‘=’ for assignment. Python does not support inline assignment, so there’s no chance of accidentally assigning the value when you actually want to compare it.

×