0% found this document useful (0 votes)
12 views8 pages

Notes

Python is a high-level, interpreted programming language created by Guido van Rossum in 1991, known for its simplicity and extensive libraries. It supports various programming paradigms, including object-oriented and functional programming, and is widely used in web development, data science, and automation. Python's internal workings involve compiling .py files to .pyc and executing them via the Python Virtual Machine, making it a hybrid language that is platform-independent.

Uploaded by

akshat8958
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Notes

Python is a high-level, interpreted programming language created by Guido van Rossum in 1991, known for its simplicity and extensive libraries. It supports various programming paradigms, including object-oriented and functional programming, and is widely used in web development, data science, and automation. Python's internal workings involve compiling .py files to .pyc and executing them via the Python Virtual Machine, making it a hybrid language that is platform-independent.

Uploaded by

akshat8958
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

python-->interpreted and compiled INTRODUCTION

line by line, easy debugging

Python was created by Guido van Rossum, and first released on February 20, 1991.
While you may know the python as a large snake, the name of the Python programming
language comes from an old BBC television comedy sketch series called Monty
Python's Flying Circus.
"It is high level programming language known for its simplicity and large library
and it is developed by guido van rossun in 1991 "
use in web dev,ds,da,aiml, automation
and its syntax is easy to learn for example a+b;
use in hositals, banks, so python is everywhere.
Reason---->It is easy to learn
hybrid language, cross platform means run in different operating system, have huge
library
It is open source , it also support oop and fuction programming
Scalable and fast
web developer by django and flask, ds by panda, machine learning, cyber security
specialist, automation engineer, devops engineer, game developer pie game ,embedded
system engineer
.py extension use to save python file

//Internal working of python


.py file convert into .pyc file by compiler on fly means memory after than
interpreter (JIt) convert this code machine code which run by pvm python virtual
machine so interpreter have not to check the error in code
so python is HYBRID language like java.
platform dependent

//Input taken in python


num=input("Enter your nuber:;")
int_num=int(input("Enter number"))
//Variables and datatypes
Variable are the name of memory location where we store different type of value
not start with number, no spcial symbol use except _
no whitespace
comments-># single line,
""" multi line comment """

//Datatypes defines what type of value variable store


//to find which type of datatype we can use type fuction
1)numeric types
a)int -->whole number 100 -33
b)float -->decimal value 1.11
c)complex --->real and imginary part ex-->a+bj,3+4j
2)boolean type --use for logical operation
of two type
a)True
b)False

3)None --express absence of value means nothing is present in this variable


use for update data later no confirm to which type of data store in future

4)Sequence type --->order collection of items can store multiple value in single
variable
have 3 type---
a)string-->sequence of character in single quotaion or double quotatin
they are immutable
b)list-->is muttable
c)tuple-->is immutable use paranthesis

5)Sets-->unordered collection of unique items


a)set-->muttable and use curly braces
b)frozenset---->immutable

6)Mapping data type


a)dictionary-->key value pair
use curly braces hear differece from set that it store in key value form

OPERATRORS IN PYTHON
on which operation perform operands
order of operation in python
PEMDAS-paracthesis,Exponent(**),
medium--->
Multiplication,Division, lowest--->Addition,Substraction

Arithmetic operator-->mathematical calculation +,-,*,/,//(floor division give round


figure value),%,**(exponent to calculate power)

Comparision operator--> ==,!=,>,<,>=,<= return in boolean

Logical operator-->combine multiple condition gates mein use


and - all condition must True
or - atleast one condition true
not - inverts

Assignment operator---> =,+=(addition assignment),-=,*=

Identity operator-->compare memory location is-return true if both have same


memory location,
is not -->return true is both have not same memory location
range -5 to 256 store in cache

Membership operator--->check whether value is exist in sequence operator or not


note here we deals with sequence
in -->return true if found value
not in-->return true if not found value

CONDITIONAL IN python
conditional-->if,elif,else
for while else suite
nested
infinite loop
pass
continue
break
assert return

if syntax-->
if condition:
statements
looping :for,while
while syntax
while condition:
code executed

for in----->use to iterate over sequence

Note -->range is special fuction which contain start,end and updata


here end is exclusive
note if upadate or step not pass then it will run but always inc by 1 default

break statements---->to stop loop immediately


continue---->to skip particular iteration

pass--->nothing do only help to write in future so that code is not burst act as
dunny undefine logic

//STRING -->sequence of charcter to store text


a-z A-Z !@#$$%
immutable
indexed start from 0
for left to right +ve indexing
for right to left -ve indexing
single qoutes , double quotes,
triple qoutes this is for multi line

String are iterable

Funtion use in string


integer len()
slice(start,end-exclusive,step)-to iterate specific part of a string
syntax strname[start:end:step]

Repeating a string
str='qw'
print(str*5) then 5 times qwqwqwqwqw comes
and if (str**5)the type error comes

Concatenation by + operator

checking membership means particulare string present or not


operator use --> in return true if present,not in return true if not present

lower()-->to convert into lower case


upper()-->to convert into upper case
capitalize()-->only first word is in capital
title-->convert 1 character of each word in string
swapcase-->covert lower into upper case and vice versa

Searching and Replacing Methods


hava two method [Link]("substing")-->return occurence of that substring

splitting and jonining


return list after splitting

Checking methods use 5 method here


a) startswith()
b)endswith()
c)isalpha() check all character are alphabetic
d)isdigit() check all character are digit
e)isalnum() check all character are alphanumeric

//LIST and tuple


list -->can store multiple data item and it is not compulsory that they are of same
type organise, and perform multiple operation on the data item
characterstics---->
ordered,
muttable,
dynamic means grow and shrink,
heterongenous means store different type of element

there are 4 ways to make a list


1)square brackets
my_list=[1,2,3,4,5,"hello",True]
2)using list constructor
apply double paracthesis and pass in list means here we use list as a function
3)list comprehension
4)By range()

How to access list --by index


lst=[2,3]
print(lst[0])//2
modify by
lst[0]=6
print(lst) //output 6,3

If want to modify more than one element we can use slicing


lst=[1,2,3,4,5]
lst[0:3]means 0,1,2 index modify
lst[0:3]=10,20,30

//concatination of list
means two string merge by using + operator
lst_1=[1,2,3]
lst_2=[4,5]
result=lst_1+lst_2

//repeatation of list also possible by * operator

//memebership operator help to check element is present in list or not


in-->found return true
not in-->not found return False

//Aliasing in list
here variable point to same data and if data change by one variable then it also
affect to another this is aliasing
li1=[1,2,3]
li2=li1
li2[0]=2
print(li1)then we get 2,2,3
for not make change to another we can use copy method
means we create a separate copy into the new list or variable
li2=[Link]()

//Methods use in list


a)append-->add item at end of list
b)extend-->here to add items of one list to another it is different from
concatination bcoz two list append here we extend list and pass the data
c)insert-->remove problem of append that insert element at given position and other
element shift to next indexes
insert(pos,data)
d)remove-->data remove and from left to right
remove(dataWantToRemove)
e)pop-->remove element by index
pop(index)
f)clear-->it makes list empty
g)index-->give index of element
h)count-->count number of time that element comes
count(data)
i)sort-->sort in ascending order
j)copy-->copy the list of one data to another
k)min-->find minimum value in function
l)to find common element between two list first we use set() which convert list
into set and then use intersection()

Now see how range function create list


Note->we dealt with range only for integer number
number=list(range(1,10,1))
here list from 1,2,3,...9 create

List Comprehension-->concise,powerful and readable way to create list


[expression for item in iterable if condition]
ex:
e-operation jo perform ho
item-
iterable->sequence jis pr loop chalane wale h
condition->optional for filter

without it->
squares=[]
for i in range(1,11):
[Link](i**2)
print(square)

now see by list comprehension


square=[i**2 for i in range(1,11)]
print(square)

if want only even number


square=[i**2 for i in range(1,11) if i%2==0]
print square

//TUPLES
immutable,
heterogenous,
use {}

How to create
a=10,20,30 also tuple but not good approach
a=(10,20,30)
b={} also possible
not use modification method here

//Metod use for tuple


min, max, count, index, sorted,

//access by index
//slicing possible
a=(1,2,3,4,5,6)
print(a[Link]) output 0,1,2
start,limit exclusive,step

//DICTIONARY DATA type


store element in the form of pair
key:value
ex-->
roll number->1,2,3...
1:name,class,sec
2:name,clase,sec
3:name,class,sec
......

characterstics
key-value,
unordered before 3.7 ,now ordered
mutable means operation can be performed,
dynamic size increase or decrease
use curly-braces
we can use tuple inside key
we can use list inside key
we can use dictionary inside key

NOTE: key must be unique bcoz if key name is same then the key which is younger
override the older key data bcoz dictinary are mutable

//how to add and update new data item in key


my_dict["key"]=data
//key same jo phle se to update and add if key name is not present in dictionary
//delete data by dictionary
use del keyword
syntax:
del dic_name["key"]

//Method use in dictionary


generally 8-9 method present
a)get()-->to retrieve the value of specific key
get('key')if key present give value and if not present then it give none
get('key','Not found')-->if key not present give Not found

b)keys()--->return all key present


in tuple form

c)values()----.return all values present in dictionary

d)items()--->give all key value in the form of tuple

e)popped()---->provide key and delete that key:value pair form dictionary

f)popitem()---->delete item from last


lifo works here

g)clear()--->makes dictionary empty


//FUNCTIONS

suntax: use def keyword


def f_name():
funtion_body

//calling of function
f_name()

//Parameter and argument


Parameter variable act as placeholder
arguments value which actual are into the function

argument are of three types:


1)positional arguement -->are those argument which are passed through position wise
for example-->def fun(name,no):
funtion_body
if print here then name mein Aram and num mein 1 so it is position
wise
fun("Aram",1)

2)keyword argumente -->through keyword pass no issue of position


call time mein tell krte h
call like that
fun(no=2,name="Aram")

3)Here in parameter we define default value also so if user not pass any value then
it take that default value
for ex:
def fun(name="Aram"):
print(name)
fun()
then it by default print Aram

//return -->exit a funtion and go back to where it call, want value from function

Note-->Name of funciton meningful,length small,


avoid global variable

global varible-->not define in function, these scopes are globally


local variable--->only inside the fucntion and use only inside function

//Decorator and Generator


Decorator---> add another function in a function which dont affect on that funciton
for ex we add cheese in burger
"Add function into another wihout explicitly modifying it"

write @ where we use Decorator

Generator-->it is like vending machine


on demand value and one value generate at a time
less memory use

use yield keyword for it which tell use one at a time

also memorise order


decorator use to enhance fucntion without it
generator is use to generate the sequence of value

//Lambda function-->anonymous function means without no name,use lambda


keyword,only one exprerssion can be written in time

You might also like