Python - Points to Remember

Introduction

  • Python is an open-source object-oriented programming language
     
  • Python uses an interpreter instead of a compiler - An interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without requiring them to have previously been compiled into a machine language program
     
  • Python can be used to build packages that can be shared and reused in other programs
     
  • Python is a versatile language. It can be used to do any quick calculations for web-site development.
     
  • Python shell is an editor where we can write any command and execute it instantly. For simple calculations, we can directly write 7+8 into the Python shell and see the result (i.e., 15). 

Python Modules 

  • A Python module is a script file with the extension “.py”
     
  • Python modules contain a sequence of definitions and statements. Python executes these statements in a specific, consistent, and predictable order list. Each of the Python statements contain zero or more expressions.
     
  • To add comments to your Python script, you can use the # tag

Python Expression

  • A Python expression describes a computation, or operation, performed on data. For example, the arithmetic expression 2+1 describes the operation of adding 1 to 2. An expression may contain sub-expressions, for example, the expression 2+1 contains the sub-expressions 2 and 1.
      
  • Python evaluates an expression by first evaluating its sub-expressions, then performing an operation on the values. For example, to evaluate 2*10 + 6/3, Python first evaluates 2*10 to the value 20, then evaluates 6/3 to the value 2, then adds the two to get 22.
      
  • Python support four types of expressions (i.e., Literal, Binary, Compound, and Unary Expressions)
      
  • A literal expression evaluates to the value it represents. For example, 17, 'this is some text', 8.125 and True 
     
  • A binary expression consists of a binary operator applied to two operand expressions. A binary operator is an operator that takes two arguments (for example, + or /). For example:
  1.  2 * 5   
  2. 14 + 8  
  3. 6 == 7 => false (binary Boolean expressions)  
  • A compound expression contains multiple expressions and at least one of the operands is itself an expression. For example, 2 * 5 + 1 is equivalent to (2 * 5) + 1.
      
  • To evaluate a compound expression to a value, 1. Use the order of operations to identify the main operator (the last operator that you’ll apply). For example, the main operator in 2 * 5 + 1 is +, so 2 * 5 + 1 is an addition expression. So, 2 * 5 and 1 are two operands of + and it gives a result equal to 11. In compound expression, use parentheses to override Python’s order of operations.

Variables 

  • Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable, for example:
    1. s="Hello World";    
       
  • Variables declared are case-sensitive, for example:
    1. s="Hello Friends";    
    2. S="Hello World";   
       
    This will initialize two different variables named “s” and “S” and assign the values ‘Hello Friends’ and ‘Hello World’ to the variable ‘s’ and ‘S’ 

 Operations 

  • Python is perfectly suited to do basic calculations. Apart from addition, subtraction, multiplication and division, there is also support for more advanced operations such as:
     
  • Exponentiation: **. This operator raises the number to its left to the power of the number to its right. For example, 4**2 will give 16.
     
  • Modulo: %. This operator returns the remainder of the division of the number to the left by the number on its right. For example, 18 % 7 equals 4.

Summary

 
In this blog, we learned about some important points of Python Programming language to remember.