Sunday, November 1, 2020

CHP4

 # CHAPTER------------> TUPLES

tupl = (1,3,4,5,6,7,8,9,10)
print(tupl[1]) 
#-------------------> list aur tuples mei major  difference ye hai ki ye immutable  hai
#immutable -------------------> isse change nhi kar sakte ho aap (cannot change the values)
tupl2 = () #-----------------> ye empty tuple hai. agar aap  isse print karoge to sirf  bracket print hoga
print(tupl2)#-------------> RESULT IN OUTPUT 
tupl3 = (1,) #-------------> agar apke tuple mei single element hai to aap uuse issay print karoge
print(tupl3[0])#-------------> RESULT IN OUTPUT 
tupl = (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
# ------------> kya aap mujhe bata sakte ho ki isme kitne one ha
print(tupl.count(1))# ye function apko batane mei help karega ki kitne one hai apke tuple mei,-------------> RESULT IN OUTPUT 
tupl4 = (1,2,3,5,6,7,8,9,4)
print(tupl4.index(4)) # for example agar mujhe find iin nine digits numbers mei se number 4 kaha par hai to mei use karunga -------------> RESULT IN OUTPUT
''' 
fruit1 = input("Enter fruit number1\n")
fruit2 = input("Enter fruit number2\n")
fruit3 = input("Enter fruit number3\n")
fruit4 = input("Enter fruit number4\n")
fruit5 = input("Enter fruit number5\n")
fruit6 = input("Enter fruit number6\n")
fruit7 = input("Enter fruit number7\n")
'''
#  note down this short keys
# 1.for comment = ctrl + /
# 1.for pasting the line in a row = alt + shift + down arrow key
# 1.for moving the line  = alt + down arrow key / up arrow key
# 1.for selecting a multiple line  = ctrl + shift + down arrow / up arrow key 
# fruitlist = [fruit1,fruit2,fruit3,fruit4,fruit5,fruit6,fruit7]
# print(fruitlist)
'''
student1 = int(input("Enter students number1\n"))
student2 = int(input("Enter students number2\n"))
student3 = int(input("Enter students number3\n"))
student4 = int(input("Enter students number4\n"))
student5 = int(input("Enter students number5\n"))
student6 = int(input("Enter students number6\n"))
student7 = int(input("Enter students number7\n"))
mylist = [student1,student2,student3,student4,student5,student6,student7]
mylist.sort()
print(mylist)
a = [3,4,5,75,6,9,5,7,8,9,14]
print(sum(a))
b = a.count
print(b)
'''
dictionary = {
    "ashutosh":"a writer of this program",
    "windows""a operating system design by microsoft",
    "marks": [1,3,4,5,6,7,8,9,5],
    "anotherdict" :{"13""a number" },
    12
    }
print(dictionary['ashutosh']) # agar apko dictionary mei se koi word ka meaning dekhna hai to aap ye function use kar sakte ho 
print(dictionary["windows"]) # agar apko dictionary mei se koi word ka meaning dekhna hai to aap ye function use kar sakte ho 
print(dictionary["marks"]) # agar apko dictionary mei se koi word ka meaning dekhna hai to aap ye function use kar sakte ho 
print(dictionary["anotherdict"]["13"]) # agar apko dictionary mei se koi word ka meaning dekhna hai to aap ye function use kar sakte ho
dictionary["marks"] = [1,3,4,5,6,8,3345,6667# dictionary ko aap change kar sakte ho like this  
print(list(dictionary.keys())) # Last mei bracket lagana na bhule
# print(list(dictionary.keys)) # Last mei bracket lagana na bhule
print(dictionary.items()) # Last mei bracket lagana na bhule
print(type(dictionary.keys())) # Last mei bracket lagana na bhule
print(dictionary.values()) # Last mei bracket lagana na bhule
ddr = {
    "sagar":"friend"
# har key aur value ke baad double quation mark lagaye 

dictionary.update(ddr)
print(dictionary) # Last mei bracket lagana na bhule
print(dictionary.get("ashutosh2")) # ye error throw nhi karega ye output none de de ga kyuki hamne yaha par get function k use kiya hai.  
# --------------------------------------------------------------------------------------------SETS
'''print(dictionary["ashutosh2"])''' # ye wala error throw karega 
sets = {1,3,5,7,9,1}
print(sets) # sets mei repitation nhi hona chahiye 
#how to create a empty set 
a = set() # aap is tara se bhi set bana sakte ho 
a.add(1#question = define the set 
a.add(16# answer = set is a collection of non repetitive numbers 
a.add(15)
a.add(3)
a.add(4)
a.add(7)
a.add(5)
a.add(2)
print(type(a))
print(a)
print(len(a))
b = {1,6,7}
a.remove(1)# removes the specific number from the set 
# a.remove(13)  this will throw a error because the number 13 is not mentioned in a set 
print(a.pop()) # removes a random  numbers from set 
print(a) # lets see the result : in output
b.clear()
print(b)
'''
dic = {
    "asshole" : "chutiya",
    "non-sense" : "gandu"
}
vvv = input("enter your word\n") 
print("the answer is", dic[vvv])
print("the answer is", dic.get(vvv)) agar apne ki galat key dali hai to ye error throw nhi karega   
'''
SSS = {18,"18"}  
''' QUESTION = CAN WE GET THE BOTH  THE NUMBERS IN OUTPUT
ANSWER =  YES WE CAN BECAUSE IF YOU CAREFULLY IN SET BOTH
THE NUMBERS HAVE DIFFERENT DATATYPES FOR PYTHON BOTH OF THIS DIFFERENT VARIABLES.
''' 
print (SSS)
# completed with chp5 ------------------> NEXT

No comments:

Post a Comment