Python Notes: From Import

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Python notes

Print (max (3,4)) for 4


Same can be applied as
Min
Round
Abs for absolute negative will become positive
% between 3 numbers for the remainder

For more math functions


from math import *

print(floor(3.7))= 3
similar ceil for opposite
sqrt for squire root

for take the input from the customer


name = input("Enter you name: " )
age = input("Enter you age: " )
print("Hello " + name+ "! you are " +age+ " year old")

Joining two lists


lucky_numbers = ["2","35","35", "33"]
friends= ["hero","zero","ajay","raju", "viraj"]
friends.extend(lucky_numbers)
print(friends)

we can use friends.append to add the new friend in the list but it will
add in the end only
to add in between we can use
friends.insert(1,”Dinesh”) where 1 shows position and second friends
name
friends.remove(“name”) to remove the specific friends and
friends.clear to delete all the friends
friends.pop() to remove last person of the list

print(friends.index(“name”)) it gonna tell index of the person


print(friends.count(“name”)) to know the number of same name in the
list.
print(friends.count()) to short the list according to name
friends2 = friends.copy()
Tuple
coordinates= (4,5)
print(coordinates)
in list
coordinates= [4,5]
coordinates[1] = 15
print(coordinates)

the main difference in tuple and list is that data in tuple cannot be
changes but can be done in case of list.

functions
def say_hi(name, age):
  print("Hello " + name + ", you are " + age +",")

say_hi("mike", "35")
say_hi("hero", "15")

def cube(num):
  return num*num*num

print(cube(5))

if statement
is_Nidhi = True
is_Neha = False

if is_Nidhi or is_neha:
  print("You are great women")
else:
  print("you r bad women")

if and or statement
is_Nidhi = True
is_Neha = False

if is_Nidhi and not(is_Neha):
  print("you are my women")
elif not(is_Nidhi) and is_Neha:
  print("you are my Di")

else:
  print("you r bad women")

Calculator of better level


num1 = float(input("Enter your first number: "))
op = input("Enter your first number: ")
num2 = float(input("Enter your second number: "))

if op == "+":
  print(num1 + num2)
elif op == "-":
  print(num1 - num2)
elif op == "*":
  print(num1 * num2)
elif op == "/":
  print(num1 / num2)
else:
  print("Invalid input")

while loop

You might also like