Practice Python
Practice Python
print(“hello world”)
INDENTATION (SPACE)
if 5 > 2:
print("Five is greater than two!")
#indentation plays a important role.
OPERATORS
>>> #OPERATORS
>>> #ADDITION
>>> x = 5
>>> y = 3
>>> print(x+y)
>>> #SUBTRACTION
>>> x = 5
>>> y = 3
>>> print(x - y)
>>> #MULTIPLICATION
>>> x = 5
>>> y = 3
>>> print(x*y)
15
>>> #DIVISION
>>> x=12
>>> y=3
>>> print(x/y)
4.0
>>> #MODULES
>>> x=5
>>> y=2
>>> print(x%y)
>>> #operator"="
>>> x=5
>>> print(x)
>>> #"+="
>>> x=5
>>> x+=3
>>> print(x)
>>> #"-="
>>> x=5
>>> x-=3
>>> print(x)
>>> # "*"
>>> x=5
>>> x*=3
>>> print(x)
15
PRINT DATA TYPES
x = str("Hello World")
print(x)
print(type(x))
x = int(20)
print(x)
print(type(x))
x = float(20.5)
print(x)
print(type(x))
x = complex(1j)
print(x)
print(type(x))
print(x)
print(type(x))
x = tuple(("apple", "banana", "cherry"))
print(x)
print(type(x))
CREATING VARIABLES
>>> X=5
>>> T="JOHN"
>>> print(X)
>>> print(T)
JOHN
>>>
>>> print(x)
Orange
>>> print(y)
Banana
>>> print(z)
Cherry
>>>
>>> b=200
>>> if b>a:
b is greater than a
>>>
>>> if b > a:
elif a == b:
NESTED IF
>>> x=41
print("above ten")
if x > 20:
else:
above ten
>>>
WHILE LOOP
>>> i = 1
print(i)
i +=1
>>>
BREAK STATEMENT
>>> i = 1
print(i)
if i == 3:
break
i += 1
>>>
LAMBDA FUNCTION
>>> x = lambda a : a + 10
>>> print(x(5))
15
>>> x = lambda a, b : a * b
>>> print(x(5,6))
30
>>> x= lambda a, b, c : a + b + c
13
>>>
PYTHON ARRAY
>>> #CREATE AN ARRAY CONTAINING CAR NAMES:
>>> x = cars[0]
>>>
>>> print(x)
Ford
>>> print(cars)
>>> x = len(cars)
>>> print(x)
>>> cars.append("HONDA")
>>> print(cars)
>>> cars.pop(1)
'Volvo'
>>>
FUNCTIONS
#CALLING OF A FUNCTION
>>def my_function():
my_function()
ARGUMENTS
>>> def my_function(Rider):
my_function("Yogesh")
my_function("Samarth")
my_function("SWAPNIL")
Rider Yogesh
Rider Samarth
Rider Swapnil
>>
KEYWORD ARGUMENTS
>>> def my_function(child3, child2, child1):
>>
DEFAULT PARAMETER VALUE
>>> def my_function(country = "Norway"):
>>> my_function("India")
I am from India
>>> my_function()
I am from Norway
>>>