Skip to main content

Python tutorial - #5 (Operators in Python)

Membership Operators

This operator helps us to check an element is found in a sequence or not. It gives there result in Boolean value (True or False).
➥There are two types of Membership operator :-
a) in
b) not in

➢in membership operator

This membership operator returns True if an element is found in a sequence and it returns  False When an element is not found in a sequence.
Program - #1

➢not in membership operator

This membership operator returns True if an element is not found in a sequence and it returns False if an element is found in a sequence.
Program = #2

Identity Operators

This operator helps us to check whether two element are same or not. Actually, this operator compares the memory location of two object, if the memory locations are same then objects are also same otherwise the objects are not same.
                                            Memory location of an object is an integer number value which tells us where the object present in memory .
       To check the memory locations of any object we use id() function which gives an integer value.

This operator also return Boolean value (True or False) as result.
➥There are two types of Identity operator :-
a) is 
b) is not

➢is Operator

This identity operator returns True if one object memory location is same to other object memory location.While it returns False if an object memory location is not same to other object memory location. 
Program = #3

➢is not Operator

This identity operator returns True if an object memory location is not same to other object memory location. While it returns False if one object memory location is same to other object memory location.
Program = #4


Mathematical Functions

Operators are useful, when we deals with basic operation like Addition, Subtraction,Multiplication etc. But when we need to perform various advance operations like to calculate factorial, square root etc. We need a separate tool to perform this, and this tool is called math module.

Module = Module is a separate file that contains various functions,class etc. which helps us to perform a specific task.
Python contains a large amount of Module that make them so powerful.
              Math is a module that contains several functions to perform mathematical operations. If we want to use any module in our program. First, we need to import that module. so, we need to import math module first. 

We can import math module as:-
import math
➩once this is done then we can use any functions of math module.

We can also use import statement as:-
import math as m
➩In this case, we are importing math module and named it as m.

When we need to import a particular function of math module we can import it as:-
from math import factorial
➩Here, only factorial function is imported from math module.

We can also import two or more functions of math module as:-
from math import sqrt, factorial




Comments

Popular posts from this blog

Python tutorial - #4 (Operators in Python)

OPERATORS IN PYTHON The general purpose of a program is to accept data and perform some operations on the data. The data in the program is stored in variables. The next question is how to perform operations on the data. For example, when a programmer wants to add two numbers, he simply type '+' symbol. This symbol performs addition operation. Such symbols are called operators. ⇨ Operator = An operator is a symbol that performs an operation.  When an operator acts on some variables then it is called operands . Example :- a + b in the given equation '+' operator acts on two operands 'a' and 'b'. If an operator acts on single operands then it is called unary operator . And when an operator acts on two operands then it is called binary operator . And when an operator acts on more than two operands (variable) It is called Tertiary operator . ➠Classifications of Operator -- a) Arthimatic operators b) Assignment operators c) Unary minu...

Python tutorial - #6 (Control statements)

Control Statements When we write a simple program, generally it executes line by line and this execution are called sequential execution. This type of execution is suitable only for developing simple programs. It is not suitable for developing complex programs. To develop a program which contains complex logic. Then we need to execute statements according to our requirement for this we uses Control statements in which we can control the statements according to our need.  ➠ There are types of control statements in Python:- a) If... statements b) If... else.. Statements c) If...elif....else.. Statements  d) While loop  e) For loop f) Nested loop  g) Else suit h) Continue statements  i) Break statements j) Pass statements  k) Assert statements l) Return statements  ↷If... statements    Syntax:-  if condition:                 Statements Here, at first...