You are on page 1of 14

Variables and operators

Name : Jakkam Hemanth Kumar


Registration No. :22MIC7054
Variables

A variable is a named place in the memory where a programmer


stores data and later retrieve the data using the variable name.
1.Integer:
*In Python, integers are zero, positive or negative whole
numbers without a fractional part and having unlimited precision

>>> 0
0
>>> 100
100
>>> -10
-10
>>> 1234567890
1234567890
>>> y=5000000000000000000000000000000000000000000000000000000
5000000000000000000000000000000000000000000000000000000
2.Float:
The float type in Python represents the floating point number. Float is
used to represent real numbers and is written with a decimal point
dividing the integer and fractional parts. For example, 97.98, 32.3+e18,
-32.54e100 all are floating point numbers.

Example: float()
print("int to float: ", float(10))
print("int to float: ", float(-10))
print("string to float: ", float('10.2’))
print("string to float: ", float('-10.2'))

Output:
int to float: 10.0
int to float: -10.0
string to float: 10.2
string to float: -10.2
3.String:

String is a collection of alphabets, words or other characters. It is one of the


primitive data structures and are the building blocks for data manipulation.

Input:
1.str1 = 'Hello Python'  
2.print(str1)  
Using double quotes  
3.str2 = "Hello Python"  
4.print(str2)  

Output:
Hello Python
Hello Python
Hello Python Hello Python
Rules:
• A variable name must start with a letter or the
underscore character.

§ A variable name cannot start with a number.

§ A variable name can only contain alpha-


numeric characters and underscores (A-z, 0-9,
and _ )

§ Variable names are case-sensitive (age, Age


and AGE are three different variables)
Assigning to a variable:

• The assignment operator, denoted by the “=” symbol, is


the operator that is used to assign values to variables in
Python.
• A typical example of assigning a value to a variable is
the statement “int b = 3.” Here:
• “int” is the data type.
• “b” is the variable.
• "=" is the operator.
• “3” is the value
• The value stored in a variable can be updated by
replacing the old value with a new value 
Operators

There are 6 types of operators in python:


 Arithmetic Operators
 Assignment Operators
 Comparison Operators
 Logical Operators
 Membership Operators
 Bitwise Operators
Python Arithmetic Operators:
Assignment Operator
Logical Operators

Logical Operators are used to check whether an


expression is True or False
They are used in Decision making
Comparison Operator
Identity Operators
In Python, is and is not are used to check if two values are
located on the same part of the memory. Two variables
that are equal does not imply that they are identical.
Bitwise Operators
Bitwise operators act on operands as if they were strings
of binary digits. They operate bit by bit, hence the
name.
For example, 2 is 10 in binary and 7 is 111.
In the table below: Let x = 10 (0000 1010 in binary)
and y = 4 (0000 0100 in binary)

You might also like