Professional Documents
Culture Documents
Session1: Installation, Data Types, Variables
Session1: Installation, Data Types, Variables
Session1: Installation, Data Types, Variables
Variables
Installation:
>>>8+9
17
+ (addition)
- (subtraction)
%(Remainder or modulus)
/ (division)
* (multiplication)
// (quotient)
Order of preference BODMAS rule and for equivalent operators from left to right.
>>> a=5
>>> a
>>> a*3
15
>>> a/5
1.0
>>> a
>>> a=12.5
>>> a
12.5
>>>
>>> a=35
>>> b=25
>>> a=4
>>> b=2
>>> a/b
2.0
>>> a//b
>>> a%b
>>> 2**3
>>> 2*3
6
>>> a=5
>>> b=2
>>> a+b
>>> c=a+b
>>> c
Evaluating an expression
>>> 2+3*6
20
>>> 2+6/2-2
3.0
>>> 6-2+9/3*6
22.0
>>> 3+4%2
>>> 3//4%2
>>> 1-3//4%2
DATA TYPE
Most commonly used data types are
1) Integer
2) Float
3) Strings
>>>a=10
>>>type(a)
>>>a=15.6
>>>type(a)
float
>>>a='yashwanth'
>>>type(a)
str
>>> a=8
>>> str(a)
'8'
>>> type(a)
<class 'int'>
>>> a=8
>>> b=str(a)
>>> b
'8'
>>> type(b)
<class 'str'>Exceptions:
>>> a='yashwanth'
>>> a+10
a+10
c=A+b
print(c)
STRINGS:
a string is a group of alphabets or words
Replication of strings
>>> a*10
'yashwanthyashwanthyashwanthyashwanthyashwanthyashwanthyashwanthyashwa
nthyashwanthyashwanth'
'hellogood morning'
'hellogood morning'
>>> a='iglobal'
>>> a[1]
'g'
>>> a[2]
>>>'good'*'morning'
'good'*'morning'
Input Function
c=a+b
r=c*5
print(c,',',r)
if we would like to convert integer input, we have to use
cricket football 10
>>> a
10
cricket football 10
>>> a
10.0
FLOAT DATA TYPE INPUT
c=a+b
print(c)
#sample program to divide integer and float numbers
c=int(a/b)
print(c)