Posts

Conditional statement (flow control)

What is flow control? Flow control describes the order in which statements will be executed at runtime. Conditional statement  if if else else if (elif) if with condition  code:- age=int(input("enter your age:")) if age<18:     print('you are too young') elif age>50:     print('you are too old') else:     print('finding a girl for you')

Python operator

What is operator? Operator is nothing but symbols that perform certain task. Various set of operators in python:- 1)Arithmetic Operator a=50 b=5 print(a+b) print(a-b) print(a*b) print(a/b) print(a//b) print(a**b) 2)Relational Operator a=50 b=5 print(a<b) print(a>b) print(a<=b) print(a>=b) print(a==b) print(a!=b) 3)Logical Operator a=50 b=5 print(a<b and a>b) print(a>b or a<b) print(not(a<b and a>b)) 4)Bitwise Operator(applicable for int and bool value only) a=5 b=6 print(a&b) print(a|b) print(a^b) print(~b) print(a>>1) print(1<<b) 5)Assignment  Operator a=111 print(a) 6)Special Operator  Identity operator (is , is not)  Membership operator (in , not in) 

Python identifier

What is identifier? Identifier is nothing but name in python program. it can be class-name , function-name , variable-name , module-name. Allowed character  Alphate (uppercase or lowercase)  Digits (0-9)  Underscore ( _ ) var1=10 Var2=20 VAR_3=30 print(var1) print(Var2) print(VAR_3) Should not be start with digit. 1var=10 print(1var) SyntaxError: invalid decimal literal Case sensitive var1=10 print(VAR1) NameError: name 'VAR1' is not defined We can not use reserve word. True=20 print(True) SyntaxError: cannot assign to True

Python Dictionary

 What is dictionary? Dictionary is a data structure in which we represent a group of object as key value pair. Indexing & slicing not work. Insertion order is preserved. Heterogenous elements are allowed. Mutable in nature. Key must be unique but duplicates value are allowed. #Empty dictionary var={} print(type(var)) var=dict() print(type(var)) #Dictionary with item var={"Name":"Rishikesh","Age":"25"} print(var) #pop is use to delete item from dictionary var={"Name":"Rishikesh","Age":"25","cast":"obc"} var.pop("cast") print(var) var={"Name":"Rishikesh","Age":"25","cast":"obc"} print(var.pop("cast")) print(var) #get method use to get the value of the key var={"Name":"Rishikesh","Age":"25","cast":"obc"} print(var.get("cast")) print(var) #...

Python set

What is set? set is a data structure which is also called collection of item in which we can represent a group of unique value as a single entity.  we write the item of set inside the "curly braces {}". insertion order not preserved. indexing and & slicing not work. Heterogenous elements are allowed. Mutable in nature. Duplicate are not allowed. #empty set var=set() print(type(var)) #Set with item var={10,20,50.5,"rishi",True} print(type(var)) print(var) #add method for adding one item  var={10,20,50.5,"rishi",True} var.add("parisa") print(var) #update method for updating one or more item var={10,20,50.5,"rishi",True} var.update(["parisa","shiansh"]) print(var) #pop method for deleting item  var={10,20,50.5,"rishi",True} print(var.pop()) #remove method for deleting particular item  var={10,20,50.5,"rishi",True,"parisa"} var.remove("parisa") print(var) #clear method for clea...

Python tuples

Image
 What is tuple? Tuple is a data structure which is also called collection of item in which we can store anything like string , float , integer. We write the item of the tuple inside "parenthesis ()" and each item separated by " comma ,". Duplicates are allowed. Immutable in nature.   1)Empty tuple 2)tuple with items 3)To find the length of the tuple use len. function. 4)copy 5)index= by using we can find out the index number of the item.

Python List

Image
What is list? List is a data structure which is also called collection of item , in which we can store anything like (string,float,integar) We write the item of list inside " squared brackets[] " and each item separated by " comma , " Duplicates are allowed in list. Mutable in nature. 1)Create empty list 2)list with some values 3)indexing = indexing start with 01234  4)slicing = slicing work till -1  5)count = it is use to count present item in list. 6)index = it is  use to know location of the item in list. 7)insert = it is use to add item in list on particular position it required the index position and variable 8)pop = it is use to delete the item from the list  9)extend = it is use to add item at the end of the list 10)copy = Copy use to copy one list to another list 11)sort = sort is use to arrange list in ascending or descending order it work in only for numerical value. 12)reverse=it use to see list in reverse order. 13)Nested list = it is use to add list in...