• Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.

  • Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms

  • If you’re a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow.


  • Python is just the language for you.


  • You could write a C/C++/Java program, but it can take a lot of development time to get even a first-draft program. Python is simpler to use, available on Windows, Mac OS X, and Unix operating systems, and will help you get the job done more quickly.


  • Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than shell scripts or batch files can offer. On the other hand, Python also offers much more error checking than C, and, being a very-high-level language, it has high-level data types built in, such as flexible arrays and dictionaries.


  • Because of its more general data types Python is applicable to a much larger problem domain than Awk or even Perl, yet many things are at least as easy in Python as in those languages.


  • Python allows you to split your program into modules that can be reused in other Python programs.


  • It comes with a large collection of standard modules that you can use as the basis of your programs — or as examples to start learning to program in Python.


  • Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary.


  • Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs


  • The high-level data types allow you to express complex operations in a single statement;


  • Statement grouping is done by indentation instead of beginning and ending brackets;


  • No variable or argument declarations are necessary.


  • Python is extensible: if you know how to program in C it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may only be available in binary form (such as a vendor-specific graphics library).



  • You can use Google colab to execute and write programs without any installations. All programs of this tutorial are in google colab.

  • Comments in Python start with the hash character, #, and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character.

  •  # this is the first comment
    spam = 1  # and this is the second comment
              # ... and now a third!
    text = "# This is not a comment because it's inside quotes."
    
  • The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses (()) can be used for grouping. For example:

  •  
     
    >>> 2 + 2
    4
    >>> 50 - 5*6
    20
    >>> (50 - 5*6) / 4
    5.0
    >>> 8 / 5  # division always returns a floating point number
    1.6
     
     
    

  • The integer numbers (e.g. 2, 4, 20) have type int, the ones with a fractional part (e.g. 5.0, 1.6) have type float.


  • Division (/) always returns a float. To do floor division and get an integer result (discarding any fractional result) you can use the // operator; to calculate the remainder you can use %:


  •  
    >>> 17 / 3  # classic division returns a float
    5.666666666666667
    >>>
    >>> 17 // 3  # floor division discards the fractional part
    5
    >>> 17 % 3  # the % operator returns the remainder of the division
    2
    >>> 5 * 3 + 2  # result * divisor + remainder
    17
     
    

  • With Python, it is possible to use the ** operator to calculate powers


  •  
    >>> 5 ** 2  # 5 squared
    25
    >>> 2 ** 7  # 2 to the power of 7
    128
     
    
  • The equal sign (=) is used to assign a value to a variable.


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

  • If a variable is not “defined” (assigned a value), trying to use it will give you an error.


  •  
    >>> n  # try to access an undefined variable
    Traceback (most recent call last):
      File "", line 1, in 
    NameError: name 'n' is not defined
     
    

  • There is full support for floating point; operators with mixed type operands convert the integer operand to floating point:


  • In interactive mode, the last printed expression is assigned to the variable _.


  •  
    >>> 4 * 3.75 - 1
    14.0
    >>> tax = 12.5 / 100
    >>> price = 100.50
    >>> price * tax
    12.5625
    >>> price + _
    113.0625
    >>> round(_, 2)
    113.06
    
     
    

  • This variable should be treated as read-only by the user. Don’t explicitly assign a value to it — you would create an independent local variable with the same name masking the built-in variable with its magic behavior.


  • In addition to int and float, Python supports other types of numbers, such as Decimal and Fraction. Python also has built-in support for complex numbers, and uses the j or J suffix to indicate the imaginary part (e.g. 3+5j).