This document discusses data types and operators in Python. It describes the main data types in Python including numeric, string, list, tuple and dictionary. It also explains arithmetic operators like addition and subtraction, relational operators for comparisons, and logical operators like AND and OR. Numeric data types can be integer or float, strings are collections of characters, lists are comma separated values in brackets, tuples are similar to lists but within parentheses, and dictionaries contain key-value pairs within curly braces. Common operators in Python are used for math operations, comparisons, and logical evaluations.
2. What is a data type?
In computer science and computer
programing a data type or simply type
is a classification of data which tells
the compiler or the interpreter how
the programmer intends to use the
data.
3. Python supports the following
data types.
NUMERIC
STRING
LISTS
TUPLES
DICTIONARIES
4. NUMERIC
It includes only number which can be
either integer or decimal.
It is of two types:
1. Integer.
2. Float.
5. Integer:
Python allows all the positive and negative
numbers to be used with ‘int’ keyword.
Float:
It is used to specify fractional numbers with
the keyword ‘float’.
6. STRING
In python it is the collection of characters which is
called string and it can hold any type of known
characters like symbols, numbers, letters etc.
Example:
a=“hello”
b=“how are you”
print(a+b)
o/p:
hello how are you
7. LISTS
In python lists represents ‘coma’ separated values
between square brackets ‘[ ]’.
Example:
a[1,2,3,4,5,6,7,8,9]
a[1]=50
8. TUPLES
They are also list of values separated by ‘coma’
within parenthesis ‘( )’.
Example:
a(1,2,3,4,5,6,7,8,)
a(1)=30
9. DICTIONARIES
It is an ordered set of key : value pairs
within flower bracket’{ }’.
Example:
a{1,2,3,4,5,6,7,8}
a{1}=20
10. OPERATORS
Python supports the following operators:
1. Arthematic operators.
2. Rational operators.
3. Logical operators.
11. ARTHMATIC OPERATORS
It includes:
+, -, /, %, *, //, ** .
1. /: For the division to get quotient.
2. %: For division to get remainder.
3. //: (Floor division) it is for division.
But the fractional part is ignored.
4. **: It is for power calculation.
12. RELATIONAL OPERATORS
represent ‘nIt includes:
>, <, <=, >=, =, ==, !=.
1. = : It is for assigning the value with the variable.
2. == : It is to compare for exact matching.
3. != : Here,’!’ is to ot’.
Example:
a==5
If a=3 , a=5 (when we substitute)
3==5 (wrong) , 5==5(correct)
13. LOGICAL OPERATORS
It includes ‘and’, ‘or’, ‘not’.
1. And: it is called logical ‘and’ which evaluates to true. If
both the inputs are true other wise false.
2. Or: it is called logical ‘or’ and evaluates to true if any
one of the input is true otherwise false
A B A &
B
0 0 0
0 1 0
1 0 0
1 1 1
A B A or B
0 0 0
0 1 1
1 0 1
1 1 1
14. 3. Not: It is called negation in which
there is only one input and the output is
true if input is false and vise versa.
A ! A
0 1
1 0
15. IDENTITY OPERATORS
In python ‘is’ and ‘is not’ are called identity
operators
‘is’ will give the output as true if both the variable
point to the same location, otherwise false.
‘is not’ will give the output as true if both the
variables doesn't point to the same
location/otherwise false.