Posts

Showing posts from June, 2023

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...

Python datatype & variable

Image
What is datatype? Datatype represents the different kinds of values that we stored on the variable.  Datatype:-Numbers,string,dict,set,list,tuple 1)we do not need to specify the data type explicity based on values types allocated automatically. 2)python is dynamically typed language. What is variable? Variable is the name of memory location where we can stored different type of values.  for example we want to print ankit wee write   print('ankit')   but if we write again and again so named ankit as a a='ankit' print(a) ankit Some example of list,tuple,set,dict.

Python keywords

Image
What is keyword? Keywords are the reserved words whose meaning already defined in the python interpreter. each keyword  has special meaning in python. 1) We can't use a keyword as a variable-name , method-name or any other identifier. 2) Python keywords are the case sensitive. 3) There Are total 35 Keywords:-['False','None','True','and','as','assert','async','await','break','class','continue','def','del','elif','else','except','finally','for','from','global','if','import','in',is','lambda','nonlocal','not','or','pass','raise','return','try','while','with','yield']

Python comments

Image
Python Comments :- Comments are nothing but ignorable part of python program that are ignored by the interpreter. It enhance thee readability of code. There are 2-type of comment:- 1) Single line comments #hello world  2) Multi line comments '''hello world                           hello world                            hello world'''

Input/Output

Image
Input/Output For input we have to enter data (). for output we have to use Print ().  Input function 1. In python programs, we use the input() function to take any kind of data input from the user through the keyboard. 2. The input() function waits for the user's input and as soon as the user enter the data and process the enter key , the input () function reads that data and assigns it to the variable.   Syntax :- Var-name = Input ()  Print() function is used to display the output on the consol. Input() function always return string value. 1) var=input("enter data") 2) enter data50  3) print(type(var)) For changing the type of input enter int before Input() 1) var=int(input("enter data")) 2) enter data100 3) print(type(var)) For changing the type of input enter float before Input() 1) var=float(input("enter data")) 2) enter data12.50 3) print(type(var)) For changing the type of input enter bool before Input() 1) var=bool(input("enter data"))...

What is python?

What is python? Python is a general purpose dynamically typed high level language developed by 'Guido van Rossum' in the year 1991 at CWT in Netherland. Syntax :- print('Hello world') Installation of Python https://www.python.org/downloads/ Why named Python? Guido van Rossum was a fan of the popular comedy show " Monty python's flying circus " broadcasted by BBC (1969-1974) so he decided to pick named his language as python. Feature of python :- 1. Simple & easy to learn. 2. Freeware & open source. 3. Platform independent. 4. Rich Library. 5. Portable. 6. Embedded. 7. Extensible. 8. Interpreted.

Python Details

 Flavors of Python   1. Jpython  https://www.python.org/ 2. Pypy  https://www.python.org/ 3. Anaconda Python  https://www.anaconda.com/download 4. Cpython  https://www.python.org/ Core python :- 1. What is Python ? 2. Installation of Python. 3. Datatype & Variables. 4. Reserved Word. 5. Type Casting. 6. Input/Output. 7. Operators. 8. Command-line Arguments. 9. Control Flow. 10. Function.  11. Modules. 12. Class & Objects  13. Inheritance. 14. Polymorphism. 15. Encapsulation.  16. Data abstraction.