Python is that one particular language which is gaining popularity day by day!! I have started learning this language and welcome you all to join my journey; where I'll be documenting my notes in the form of a blog for all of us. This is the first article in Python for Beginners
series. So, let's get started!!!
Python is an interactive programming language. Popularity : Simple syntax which make programs easy to read and write!!
IDLE - Integrated Development and Learning Environment It is an interpreter for python consisting of a python shell and python editor.
- Python editor - allows us to work in a script mode.
- Python shell - an interactive interpreter in which code is written at the
>>>
prompt and with a press ofENTER
key, it responds with the computation result. For example The text to be printed is enclosed within' '
which do not get displayed in the output. The>>>
prompt indicates that the shell is waiting for a user command.
Python as Calculator - arithmetic operators
Operators used in python are :
+
to print the sum of operands.-
to print the subtraction result of operands. It is also used as the negation operator to print the negative value of an input.*
to print the product of operands./
to print the division result of operands which will always be a real number ( fraction or decimal).//
to print the division result of operands which will be an integer (non-fraction or non-decimal). To print a real number, either one of the operands must be a real number.%
to print the remainder of the division of operands (modulus)**
to print the exponential result of operands (to the power of )
Associativity of operators
A property that determines the evaluation of operators of the same precedence.
- Left associativity : The operators are evaluated from left to right in an expression.
- Right associativity : The operators are evaluated from right to left in an expression.
All the operators except the exponentiation operator
**
are evaluated from left associative operators. The ** operator is a right associative operator.
The first example 2 ** 3
gets evaluated as 2 ^ 3 i.e. 8.
The second example 3 ** 2 ** 2
gets evaluated as 3 ** (2 ** 2)
i.e 3 ** 4
i.e. 81.
Precedence of arithmetic operators
( )
Parenthesis
**
Exponentiation
-
Negation
/
Division
//
Integer division
*
Multiplication
%
Modulus
+
Addition
-
Subtraction
This order of precedence decreases from top to bottom i.e. parenthesis have the highest precedence whereas subtraction operation has the lowest!
Finishing off with the the arithmetic operators, I will be starting with the logical and relational operators in the next blog. Till then, try out these concepts and play with the operators to understand better!!