Quick actions

cmd+k|ctrl+k

Navigation

Languages

Basics 1

Snippet info

Language

Python

Visibility

public

Author

hamdaankhan098

Created

2026-06-17T10:57:12.685574Z

Updated

2026-07-12T19:41:03.187207Z

#operater precedance

print((20-3)+2 ** 2)

#()
#**
#* /
#+ -

print(bin(5))

print(int('0b101' , 2))


#variables
#rules:-snake_case
  #     start with lowercase or uppercase
  #     letters , numbers, underscores
  #     dont owerwrite keywords
  
iq = 160
user_age = iq/4
a = user_age
print(a)

  
 #Constants
 #PI = 3.14
 
 #assign value
a,b,c = (1,2,3)
 
print(a)
print(b)
print(c)


# Expessions and statement
  
 
# augmented assignment oprator
some_value = 7
some_value += 2 #it can be subtracted, multiplied, divide by same manner

print(some_value)


#strings

print(type('hi hello there45'))

first_name = 'hamdaan'
last_name ='khan'
full_name = first_name + ' ' +last_name

print(full_name)

# string catenation

print('hello' + ' ' + 'Khan')  #it will only work on stings like ither name will not be applied (ex no.)


# Type conversion
a = str(100)
b = int(a)
c = type(b)
print(c)


#Escape sequence
Weather = "\t It\'s \"kind of\" sunny \n hope you have a good day!"

print(Weather)

#Formaed srings
# Old ways--->
name = 'khan'
age = '18'
print('hi '+ name +'. You are ' + str(age) + ' years old')

#New way--->
print(f'hi {name}. you are {age} years old')

#STRING INDEXES
selfish = '01234567'
          #01234567
          
      #[start:stop:stepover]
print(selfish[0:8:1])
print(selfish[1::])
print(selfish[:5])
print(selfish[:-5])


selfish = selfish + '8'
print(selfish)


greet = 'heloooo'
print(greet[0:len(greet)])

quote = 'to be or not to be'
print(quote.capitalize())  #there are mny more tools like cpitalize to use

print(quote.find('or')) # also there are more like replace and many opt 


#booleans
name = 'khan'
is_cool = False

is_cool = True

print(bool(1))
print(bool(0))


#ex :--->

birth_year = input('what year were you born?')

age = 2026 - int(birth_year)

print(f'your age is: {age}')



username = input('what is your username?')
password = input('what is your password?')

password_length = len(password)
hidden_password ='*' * password_length

print(f'{username}, your password, {hidden_password}, is {len(password)}')


#lists
#Ex :-
#li = [1,2,3,4]
#li = ['a', 'b','c']
#li = [1,2,'a',true]

#Data structure :--> its use is to organise the information or data like a folder

amazon_cart = ['notebooks', 'glass']
print(amazon_cart[1])

#List slicing
amazon_2cart = ['grapes',
               'oil',
               'laptop',
               'bottle'
               ]
               
amazon_2cart[0] = 'banana'
new_cart = amazon_2cart[:]
new_cart[0] = 'apple'
print(amazon_2cart)
print(new_cart)

 #matrix
matrix = [
     [1,3,1],
     [0,1,0],
     [1,0,1]
     ]

print(matrix[0][1])

basket = [1,2,3,4,5]

#adding
basket.insert(3,99)
new_basket = basket.insert(3,99) #insert modifies list doesnt make a new copy
print(basket)                    #also there is a extend func which just extends the list
print(new_basket)

#removing 
bucket = [1,3,5,7,9]
new_bucket = bucket.extend([99])
bucket.pop()
bucket.pop(3) #remove ffunc remove whatever the speecific value given
              #clear func clears the comp bucket
print(bucket)
              #there are more keywords like index(start and stop)
              #and count which gives the count of object present 
#there are more func like count which gices the count in your input

bag = ['a','b','x','c','d','e','c']
#bag.sort() is also can be used
new_bag = bag[:]
bag.sort() # without sort the reverse order was'nt in perfect order
bag.reverse() 
print(bag[::-1]) #can be used to reverse tooo
print(sorted(new_bag))

print(list(range(5,102))) #if dont give a start value its gonna start from zero

#joining
sentence = ' '

new_sentence = sentence.join(['hi', 'my', 'name', 'is', 'sam']) #can also be phrase in = ' '.join(---) this forn
#join just adds new things to string
print(new_sentence)

#List unpacking
a,b,c, *other, d = [1,2,3,4,5,6,7,8,9]

print(a)
print(b)
print(c)
print(other)
print(d)

#use of none
#ex--> playing a game but its a start of game in which no one has a gun/weapon
weapons = None
print(weapons)

# Dictionary
dictionary = {
    'a' : [1,2,3],
    'b' : True,
    'c' : 'hello jim'
}

print(dictionary['b'])

my_list = [
{
    'a' : [1,2,3],
    'b' : 'hell',
    'c' : True
},
{
    'a' : [5,6,7],
    'b' : 'hill',
    'c' : False
    
}
    ]

print(my_list[1]['c'])

#the key of a dict must be a string ie numbers or booleans or more not a list bcoz list can be changed

docx = {
    '123' : 'hello',
    '123' : [1,2,3] #priority inc while going to next line
}
print(docx['123'])

user = {
    'box' : [4,5,6],
    'greet' : 'hello',
    'age' : '77'
}

print(user.get('age','66'))

print('77'in user.values() )
print('greet'in user.keys() )
print( user.items() )
#print(user.clear() )
user2 = user.copy()
print(user.clear() )
print(user2)
#print(user.pop) pop rmoves the actual value and prints without it

user2 = dict(name = 'joe')

print(user2)

print( user.update({'age' : 44}))
print(user)

#Tuple
#tuples is like a list but we cannot modify them

my_tuple = (3,4,5,7,9,3,5)
print(5 in my_tuple) 
print(my_tuple[1])

print(my_tuple.count(5))
print(my_tuple.index(5))

#Set ::-->unordered collection of unique obj

my_set = {1,2,3,4,5,6,7,6}
my_set.add(77)
my_set.add(5)#no. 5 didnt appear again as one item can be taken once only

print(my_set)
#set cn be converted to lists,measure len and can get boolean value like others

my_set.clear()
print(my_set)

my_set2 = {1,2,3,4,5}
your_set = {3,4,5,6,7,8}

print(my_set2.difference(your_set))
print(my_set2.discard(5))
print(my_set2)

print(my_set2.difference_update(your_set))
print(my_set2.intersection(your_set)) #print(my_set2 & your_set)
print(my_set2.isdisjoint(your_set))#recheck later
print(my_set2.union(your_set)) #print(my_set2 | your_set)

print(my_set2.issubset(your_set))
print(your_set.issuperset(my_set2))










































































INFO