You are on page 1of 10

HELLO WORLD

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))

x = list(("apple", "banana", "cherry"))

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

>>>

ASSIGN VALUES TO MULTIPLE


VARIABLES
>>> x, y, z = "Orange", "Banana", "Cherry"

>>> print(x)

Orange

>>> print(y)

Banana

>>> print(z)
Cherry

>>>

IF-ELSE CONDITIONS IN PYTHON


>>> a=33

>>> b=200

>>> if b>a:

print("b is greater than a")

b is greater than a

>>>

ELIF CONDITION IN PYTHON


>>> a = 33

>>> b = 33 #FOR ELIF CONDITION

>>> if b > a:

print("b is greater than a")

elif a == b:

print("a and b are equal")

a and b are equal

NESTED IF
>>> x=41

>>> if x > 10:

print("above ten")

if x > 20:

print("and also above 20")

else:

print("but not above 20")

above ten

and also above 20

>>>

WHILE LOOP
>>> i = 1

>>> while i < 6:

print(i)

i +=1

>>>

BREAK STATEMENT
>>> i = 1

>>> while i < 6:

print(i)

if i == 3:

break

i += 1

>>>

LAMBDA FUNCTION
>>> x = lambda a : a + 10

>>> print(x(5))

15

>>> #LAMBDA FUNCTION THAT MULTIPLIES ARG A WITH ARG B

>>> x = lambda a, b : a * b

>>> print(x(5,6))

30

>>> #LAMBDA FUNCTION THAT SUMS ARG a, b and c

>>> x= lambda a, b, c : a + b + c

>>> print(x(5, 6, 2))

13

>>>

PYTHON ARRAY
>>> #CREATE AN ARRAY CONTAINING CAR NAMES:

>>> cars = ["Ford" , "Volvo" , "BMW"]

>>> #ACCESS THE ELEMENTS OF AN ARRAY

>>> x = cars[0]

>>>

>>> print(x)

Ford

>>> #MODIFY THE VALUE OF FIRST ARRAY

>>> cars = ["Ford" , "Volvo", "BMW"]

>>> cars[0] = "Toyota"

>>> print(cars)

['Toyota', 'Volvo', 'BMW']

>>> #LENGTH OF AN ARRAY

>>> cars = ["Ford", "Volvo", "BMW"]

>>> x = len(cars)

>>> print(x)

>>> #ADDING ARRAY ELEMENTS

>>> cars = ["Ford", "Volvo", "BMW"]

>>> cars.append("HONDA")

>>> print(cars)

['Ford', 'Volvo', 'BMW', 'HONDA']

>>> #REMOVING ARRAY ELEMENTS

>>> cars = ["Ford", "Volvo", "BMW"]

>>> cars.pop(1)

'Volvo'

>>>
FUNCTIONS
#CALLING OF A FUNCTION

>>def my_function():

print("Hello from a function")

my_function()

Hello from a function

ARGUMENTS
>>> def my_function(Rider):

print(Rider + " Rave")

my_function("Yogesh")

my_function("Samarth")

my_function("SWAPNIL")

Rider Yogesh

Rider Samarth

Rider Swapnil

>>

KEYWORD ARGUMENTS
>>> def my_function(child3, child2, child1):

print("The youngest child is " + child3)

my_function(child1 = "Emil", child2 = "Tobias", child3 = "Linus")

The youngest child is Linus

>>
DEFAULT PARAMETER VALUE
>>> def my_function(country = "Norway"):

print("I am from " + country)

>>> my_function("India")

I am from India

>>> my_function()

I am from Norway

>>>

You might also like