Skip to main content

Posts

Showing posts from May, 2022

Lists in python

'''Iteamlist=["soap","face wash","deodorants",56,59] print("0",end=" =") print(Iteamlist[0],end=" \n1=") print(Iteamlist[1],end=" \n2=") print(Iteamlist[2],end=" \n3=") print(Iteamlist[3],end=" \n4=") print(Iteamlist[4])''' numbers=[ 10 , 21 , 32 , 44 ] print (numbers) print (numbers[ 0 ]) print (numbers[ 1 ]) print (numbers[ 2 ]) print (numbers[ 3 ]) '''numbers.sort() numbers.reverse() print(numbers)'''  

create string ,string slicing & other function

  mystr= "satyam is doing b-tech in ECE" # In python index starts from 0 i.e. s is at 0 place ,a is at 1st place and soo on.. mystr1= "satyamisgoodboy" '''print(mystr) print(len(mystr)) # it print the length of mystr print(mystr[4]) # It only print the latter at 4th place print(mystr[2]) # It only print latter at 2nd place print(mystr[0:6]) # It print letter from 0th se 5th place print(mystr[10:30]) # It print letter from 10th to 29th place print(mystr[0:6:2]) # here :2 indicates that it print letter from 0th se 5th place with one gap print(mystr[0:6:3]) # here :3 indicates that it print letter from 0th se 5th place with two gap print(mystr[:5]) # here it assume that it start from 0 print(mystr[0:]) # here it assume that it ends at length of mystr print(myst...

taking input from user and doing arithmetic operations

  '''print("Enter your name") a=input() print("hello ",a)''' '''print("Enter number") a=float(input() ) # here input a stores str print("enter number") b=float(input()) # here input b stores str print("the sum is",float(a)+float(b)+10) print("the difference is",float(a)-float(b)+10) print("the product is",float(a)*float(b)+10) print("the quotient is",float(a)/float(b)+10)'''

variables,arithmetic operations & typecasting

  var1= "hello," var6= "satyam" var7= 32 var8= "2" var9= "6" var10= 3.54 '''var2="4" var3="6.75" var4=4 var5=6.75''' """print(var1) print(type(var1)) print(type(var2)) print(type(var3)) print(type(var4)) print(type(var5))""" # Arithmetic operation '''print(var4+var5) print(var4-var5) print(var4*var5) print(var4/var5)''' #print(var1+var6) # showing no error #print(var1-var6) # after putting - it shows error #print(var1+var7) # showing error as 32 must be under "" #print(var1+var8) # showing no error #print(var1-var8) # showing error as we can,t subtract srt(string) # we going to use typecasting to convert str into int ,int into float & float into int '''print(int(var8)+int(var9)) print(int(var8)+int(var10)) print(float(var8)+float(var10))''' # printing hello,world n ti...

print function and escape sequance

"""print("thank you" , end="\n ") print("thank you" , end=",\n") print("thank you" , end="????\n\n") print('Everyone')""" #print("hello,","world") #print("hello,\'everyone") """s = 'Hey, whats up?' print(s)""" """s = 'Hey, what \' s up?' # without \ there seems to be error print(s)""" """print("C: \\ Users\Pat\Desktop") #one extra \ is used print("C: \\ Users \\ Pat \\ Desktop") #we can also write this way""" """print(r"Backslashes \don't need to be escaped in raw strings.") # if this \ is put after string it shows error but if \\ is used no error print("Backslashes \ don't need to be escaped in raw strings."...