A clear and readable syntax
A very extensive standard library, where through additional software modules, we can add data types, functions, and objects
Easy-to-learn rapid development and debugging; the development of Python code in Python can be up to 10 times faster than the C/C++ code
Exception-based error handling
A strong introspection functionality
Richness of documentation and software community
Python can be seen as a glue language. Using Python, better applications can be developed because different kinds of programmers can work together on a project. For example, when building a scientific application, C/C++ programmers can implement efficient numerical algorithms, while scientists on the same project can write Python programs that test and use those algorithms. Scientists don't have to learn a low-level programming language and a C/C++ programmer doesn't need to understand the science involved.
You can read more about this from https://www.python.org/doc/essays/omg-darpa-mcc-position.
Python can be downloaded from https://www.python.org/downloads/.
There are many IDEs that are designated specifically for Python, including IDLE (http://www.python.org/idle), PyCharm (https://www.jetbrains.com/pycharm/), and Sublime Text, (http://www.sublimetext.com/).
Let's take a look at some examples of the very basic code to get an idea of the features of Python. Remember that the symbol
>>> denotes the Python shell:
Operations with integers:
>>> # This is a comment >>> width = 20 >>> height = 5*9 >>> width * height 900
Only for this first example, we will see how the code appears in the Python shell:
>>> a=1.5+0.5j >>> a.real 1.5 >>> a.imag 0.5 >>> abs(a) # sqrt(a.real**2 + a.imag**2) 5.0
>>> word = 'Help' + 'A' >>> word 'HelpA' >>> word 'A' >>> word[0:2] 'He' >>> word[-1] # The last character 'A'
>>> a = ['spam', 'eggs', 100, 1234] >>> a 'spam' >>> a 1234 >>> a[-2] 100 >>> a[1:-1] ['eggs', 100] >>> len(a) 4
# Fibonacci series: >>> while b < 10: ... print b ... a, b = b, a+b ... 1 1 2 3 5 8
>>>x = int(input("Please enter an integer here: ")) Please enter an integer here:
Then we implement the
ifcondition on the number inserted:
>>>if x < 0: ... print ('the number is negative') ...elif x == 0: ... print ('the number is zero') ...elif x == 1: ... print ('the number is one') ...else: ... print ('More') ...
>>> # Measure some strings: ... a = ['cat', 'window', 'defenestrate'] >>> for x in a: ... print (x, len(x)) ... cat 3 window 6 defenestrate 12
>>> def fib(n): # write Fibonacci series up to n ... """Print a Fibonacci series up to n.""" ... a, b = 0, 1 ... while b < n: ... print (b), ... a, b = b, a+b ... >>> # Now call the function we just defined: ... fib(2000) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
>>> import math >>> math.sin(1) 0.8414709848078965 >>> from math import * >>> log(1) 0.0
>>> class Complex: ... def __init__(self, realpart, imagpart): ... self.r = realpart ... self.i = imagpart ... >>> x = Complex(3.0, -4.5) >>> x.r, x.i (3.0, -4.5)