0% found this document useful (0 votes)
2 views8 pages

Python My Notes

The document provides a comprehensive overview of Python programming concepts including variables, data types, user input, type conversion, control structures (if-else, loops), functions, and data structures (lists, tuples, sets, dictionaries). It includes practical examples and exercises to illustrate the usage of these concepts. The content is aimed at beginners learning Python programming.

Uploaded by

jocktmpx4oxc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Python My Notes

The document provides a comprehensive overview of Python programming concepts including variables, data types, user input, type conversion, control structures (if-else, loops), functions, and data structures (lists, tuples, sets, dictionaries). It includes practical examples and exercises to illustrate the usage of these concepts. The content is aimed at beginners learning Python programming.

Uploaded by

jocktmpx4oxc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

print("hello world.

")

# print("hello world")
# print("hello coders")
# print("hello guys")
# use small letters for print as python is case sensitive

# name="amaan zain"
# print(name)
# dont use variables in double quotes as it will be used as String

# String,integer,float,boolean
# a=3
# b=3.0
# c=True
# d="amaan"

# excersice
# first_name="tony"
# second_name="stark"
# age=51
# is_genius=True

# user input
# name=input("what is your name: ")
# print(name)
# print("your name is "+name)

# type conversion
# python accepts every input as string type so it is neccessory for
converting into other datatype
# old_age=input("enter your old age: ")
# new_age=old_age+3
# here problem arises as old_age is of string and instead of addittion
concatination takes place
# print(new_age)
# for solving this problem we need to use int( ) or float(
)or bool( )or str( )
old_age=input("enter your old age: ")
new_age=int(old_age)+3
print(new_age)

num1=input("enter the number 1: ")


num2=input("enter the number 2: ")
sum=int(num1)+int(num2)
print("sum of "+str(num1)+" and "+str(num2)+" is: "+str(sum))

# name="amaan zain n"


# print(name.upper())
# print(name.lower())

# print(name.find("A")) # not find so return -1


# print(name.find("n"))

# print(name.replace("zain","12"))

# print("z" in name) # checks whether the letter/String is availiable in


the string and returns boolean value

print(5+2)
print(5-2)
print(5*2)
print(5/2)
print(5//2) # to prnt only the decimal part of decimal
print(5%2)
print(5**2) # to find power

result=2+3*5 # precedence is high for *


print(result)

print(5>2)
print(5<2)
print(5<=2)
print(5>=2)
print(5==2)
print(5!=2)

print(3<2 and 4>2)


print(3<2 or 4>2)
print(not 4>2)

# simple if
# age=19
# if(age>18):
# print("you are an adult")
# print("you can vote")

# if else
# age=10
# if(age>18):
# print("you are an adult")
# print("you can vote")
# print("")
# else:
# print("you are minor")
# print("you cant vote")
# elif
age=10
if(age>18):
print("you are an adult")
print("you can vote")
elif(age>3 and age<=18):
print("you are a child")
else:
print("you are minor")
print("you cant vote")

print("thank you")

# simple calculator project


num1=int(input("enter the first number :"))
num2=int(input("enter the second number :"))
op=input("enter the operator(+,-,*,/) :")
if(op=="+"):
result=num1+num2
print("the sum is :"+str(result))
elif(op=="-"):
result=num1-num2
print("the diffrence is :"+str(result))
elif(op=="*"):
result=num1*num2
print("the product is :"+str(result))
elif(op=="/"):
result=num1/num2
print("the quotient is :"+str(result))
else:
print("invalid input")
print("")
num=range(5) # range is a function used to find the numbers upto the limit
print(num) # num contain values 0 1 2 3 4

# while loop
i=1
while(i<=5):
print("amaan zain n")
i=i+1

print(10*"zain") # prints zain 10 times

# for loop
for item in range(5):
print("amaan zain n")

marks=[10,20,30,40,50]
extra=["amaan",20,400] # diffrent type can be used inside list
extra[0]=22 # replaces the value of list in a particular index
print(extra)
print(marks)
print(extra[2])
print(extra[-2]) # mminus is used to index from the end(-1 is the last
element)
print(marks[1:3]) # to find inbetween indux here 3 rd index is not
included

for score in marks:


print(score) # to print one at a time from list

# functions in list
marks.append(20.5) # insert at the end
print(marks)

marks.insert(2,15.5) # insert at a specified position


print(marks)

print(len(marks)) # print the number of elements present in marks

marks.clear() # clear list


print(marks)

student=["ab","abab","ababab","amaan","abababab"]
for s in student:
if(s=="amaan"):
break # stops the loop
print(s)
print("**************************************************")
for s in student:
if(s=="abab"):
continue # stops the executing process and continue the next
process
print(s)

# tuples are immutable list


name=("amaan","aaaa","vvvv","bbbb","bbbf","vvvv","vvvv","vvvv","vvvv") #
paranthesis is not neccessory while defining tuples
print(name)
# name[0]="zain" # cannot replace the zeroth object because tuples are
immutable

# functions
print(name.count("vvvv")) # count the number of times an instance occur
print(name.index("vvvv")) # return the first index of the instance

name={"amaan","aaaa","vvvv","bbbb","bbbf","vvvv","vvvv","vvvv","vvvv"} #
unique values are only accepted
print(name) # repeatation not printed as sets are unique
# print(name[0]) # returns error as indexing does not contain in
sets(unordered(no index))

for i in name:
print(i)# for printing we can use for loop

marks={"physics":10,"chemistry":20,"maths":30} # here key:value pair are


stored ie. instead of index we use another instance
print(marks)
print(marks["chemistry"])
marks["biology"]=100
marks["chemistry"]=1001
print(marks)
print(marks["chemistry"])
# functions are of three type:
# 1.in build
# 2.module
# 3.user defined function

# in build
# int()
# str()

# module
# import math
# print(dir(math)) # to list the function in the imported module

# from math import sqrt # use * to import all the functions


# print(sqrt(4))

#user defined
# syntax:
# def function_name(parameters):
# //do something
def sum(num1,num2):
print(num1+num2)

# we need to call the function for it to execute


sum(1,7)

You might also like