Professional Documents
Culture Documents
DAY 2 ASSINGMENT
Subtraction (-) Subtracts the value on the right from the one on
the left.
Eg. >>> 3-4
Output: -1
Multiplication (*) Multiplies the values on either side of the
operator.
Eg. >>> 3*4
Output: 12
Division (/) Divides the value on the left by the one on the right.
Notice that division results in a floating-point value.
Eg. >>> 3/4
Output: 0.75
Floor Division (//) Divides and returns the integer value of the
quotient. It dumps the digits after the decimal.
Eg. >>> 3//4
>>> 4//3
Output: 1
>>> 10//3
Output: 3
>>> 10.5%3
09-Nov-2021
Output: 1.5
Parameters:
1. object: Required. The object whose type is to be returned.
2. name: Required. A class name.
3. bases: Required. A tuple that itemizes the base class.
4. dict: Required. A dictionary which is the namespace containing
definitions for the class body.
Eg. a = ('apple', 'banana', 'cherry')
b = "Hello World"
c = 33
x = type(a)
y = type(b)
09-Nov-2021
z = type(c)
print(x)
print(y)
print(z)
print(string1*3)
print(string1*4)
print(string1*5)
String slicing operator: “[]”
Eg.
string1 = "helloworld"
print(string1[1])
print(string1[-3])
print(string1[1:5])
print(string1[1:-3])
print(string1[2:])
print(string1[:5])
String comparison operator: “==” & “!=”
Eg.
string1 = "hello"
string2 = "hello, world"
string3 = "hello, world"
string4 = "world"
print(string1==string4)
print(string2==string3)
print(string1!=string4)
print(string2!=string3)
Output: false
True
True
false
Membership operator: “in” & “not in”
Eg.
string1 = "helloworld"
print("w" in string1)
print("W" in string1)
print("t" in string1)
print("t" not in string1)
09-Nov-2021
print("hello" in string1)
print("Hello" in string1)
print("hello" not in string1)
Output: true
False
False
True
True
False
False
Escape sequence operator: “\.”
>> Dictionary
A dictionary is an unordered and mutable Python container that
stores mappings of unique keys to values.
Dictionaries are written with curly brackets ({}), including key-value
pairs separated by commas (,). A colon (:) separates each key from
its value.
works on key value elements
Eg. products = {'table': 120, 'chair': 40, 'lamp': 14, 'bed': 250,
'mattress': 100}
>> CONTROL STATEMENTS
1) SELECTIVE STATEMENTS
A) IF-LESE
a) if
b) if-else
c) if-else-if(nested if-else)
d) if-else ladder
2) ITERATIVE STATEMENTS (looping)
A) for loop
B) while loop
3) JUMPING STATEMENTS
a) break
b) continue
c) pass
d) return
e) exit
etc.