शनिवार, 27 दिसंबर 2025

Python Notes


 पायथन क्लास

साधना शर्मा द्वारा

एमएससी (आईटी

एम.फिल (सीएस

एमबीए

      To learn Python programming experience is not required.

      Provide course and Internship

      Python combo pack

      Python with machine Learning

      Python with Data Science    

निम्नलिखित सेवाएं प्रदान करते हैं:
      पायथन प्रोग्रामिंग सीखने के लिए अनुभव की आवश्यकता नहीं है।
      कोर्स और इंटर्नशिप प्रदान करें।
      पायथन कॉम्बो पैक
      मशीन लर्निंग के साथ पायथन

Top companies used Python

Google, YouTube, DropBox, FaceBook, Instagram

In C Program

#include <stdio.h>

void main()

{

 printf("Hello Sadhana ");

}

In C++ Program

#include <iostream.h>

void main()

{

 cout<<"Hello Sadhana ";

}

In Java Program

class test

{

public static void main (String {} args)

{

System.out.println("Hello Sadhana ");

}

}

In Python it is so easy

print("Hello Sadhana ");

How to install Anaconda steps

* Anaconda is a good platform to develop Python Application.

*www.anaconda.com

*click on product

*click on individual 

*then download specific version for your Operating System.

*After Installation click

Click start button and open Jupiter Notebook

OR

http://www.python.org/downloads

Python एक बहुत ही प्रसिद्ध और शक्तिशाली प्रोग्रामिंग language है जिसे 1980 के दशक में Guido Van Rossum ने विकसित किया था। यह भाषा सरल syntax और readability के लिए जानी जाती है। 

पाइथन का उपयोग web development, data science, machine learning, artificial intelligence, automation,और scientific computing जैसे कई क्षेत्रों में होता है।

यह बहुत ही अच्छी प्रोग्रामिंग लैंग्वेज है क्योंकि इसके द्वारा बहुत तेजी से एप्लीकेशन को विकसित किया जा सकता है और यह scientific computing dynamic typing तथा dynamic binding के options देता है बहुत सारीं बड़ी कंपनियां भी python का प्रयोग करती है जैसे. YouTube, Quora, Instagram तथा google आदि

सन् 1991 में पाइथन को launch किया गया. तथा जनवरी 1994 में पाइथन का पहला edition python 1.0 निकाला गया इस edition में इसके नए features जैसे lambda, map, filter आदि आये थे अभी पाइथन का new version 3.13 market में उपलब्ध है
Python एक open source है इसके लिए कोई भी पैसा नहीं लगता तथा इसके लिए किसी भी लाइसेंस की जरुरत नहीं पड़ती क्योंकि पाइथन GPL (General Public License) के अंतर्गत उपलब्ध है इसके नए version को पाइथन की official वेबसाइट से डाउनलोड किया जा सकता है
Program in Python
Write in idle or jupiter notebook 
X=10
Y=20
Z=X+Y
print(Z)
A=10
B=5
C=A-B
print C
--------------------------------------------------------
# variable
a=10
b=20
import keyboard
len(keyword.kwlist)

anaconda 3.8 version --- 35
---------------------------------------------------------
type(a)
int
a=2.5
type(a)
float
----------------------------------------------------------
a=“hello”
type(a)
str
----------------------------------------------------------
a, b, c=10,20,30
print(a, b, c)
a=int(input(“enter first number “))
b=int(input(“enter second number “))
c=a + b
print(c)
------------------------------------------------------------
# indentation
If 5>3:
print(“Hello”)
print(“Good”)
else:
print(“Wel-Come”)
print(“MLC”)
-------------------------------------------------------------
प्रोग्राम और प्रोग्रामिंग लैंग्वेज क्या है 
किसी विशिष्ट कार्य को करने के लिए कंप्यूटर द्वारा निष्पादित निर्देशों के सेट को प्रोग्राम कहा जाता है और कंप्यूटर को निर्देशों के इस सेट को निर्दिष्ट करने के लिए उपयोग की जाने वाली भाषा को प्रोग्रामिंग लैंग्वेज कहा जाता है।
Python की विशेषताएँ 
Python एक उच्च स्तरीय भाषा है। यह मुफ़्त और ओपन-सोर्स भाषा है। पायथन पोर्टेबल और प्लेटफ़ॉर्म स्वतंत्र भाषा है। पायथन केस सेंसिटिव भाषा है। पायथन में पूर्वनिर्धारित फ़ंक्शंस की एक समृद्ध लाइब्रेरी है। पायथन ब्लॉक और नेस्टेड ब्लॉक के लिए इंडेंटेशन का उपयोग करता है।
पायथन इंटरएक्टिव मोड का उपयोग करने के दो तरीके हैं: इंटरएक्टिव मोड में, 
हम सीधे >>> प्रॉम्प्ट पर एक पायथन स्टेटमेंट टाइप कर सकते हैं। जैसे ही हम एंटर दबाते हैं, दुभाषिया कथनों को निष्पादित करता है और परिणाम प्रदर्शित करता है। यह मोड त्वरित निष्पादन के लिए सिंगल लाइन कोड का परीक्षण करने के लिए सुविधाजनक है। लेकिन इंटरैक्टिव मोड में हम भविष्य में उपयोग के लिए स्टेटमेंट को स्टोर नहीं कर सकते हैं और उन्हें दोबारा चलाने के लिए हमें स्टेटमेंट को दोबारा टाइप करना होगा।
>>>12 + 4
16
>>>a=45
>>>b=10
>>>a + b
55
स्क्रिप्ट मोड: 
किसी फ़ाइल में स्क्रिप्ट मोड पायथन प्रोग्राम में, इसे सहेजें और इसे निष्पादित करने के लिए दुभाषिया का उपयोग करें। इसका एक्सटेंशन नाम है .py
पायथन डेटा प्रकार
डेटा आइटम का वर्गीकरण या वर्गीकरण हैं। यह उस प्रकार के मान का प्रतिनिधित्व करता है जो बताता है कि किसी विशेष डेटा पर कौन से ऑपरेशन किए जा सकते हैं। चूँकि Python प्रोग्रामिंग में सब कुछ एक ऑब्जेक्ट है, Python डेटा प्रकार क्लास हैं और वेरिएबल इन क्लासों के उदाहरण (ऑब्जेक्ट) हैं। पायथन में मानक या अंतर्निहित डेटा प्रकार निम्नलिखित हैं:
Numeric - int, float, complex
Sequence Type - string, list, tuple
Mapping Type - dict
Boolean - bool
Set Type - set, frozenset
स्ट्रिंग्स के लिए डेटा प्रकार 
एक स्ट्रिंग किसी भी प्रकार के ज्ञात वर्ण यानी अक्षर, संख्या और निर्दिष्ट वर्ण को धारण कर सकती है
“abcd”, “123”, “$%^”
Python में Lists
सूची वर्गाकार कोष्ठकों के बीच किसी भी डेटा प्रकार के अल्पविराम से अलग किए गए मानों के एक समूह का प्रतिनिधित्व करती है:
A=[1,2,3,4]
str=[‘a’,’e’,’i’,’o’,’u’]
str1=[‘sita’,11,12]
Tuples
Tuples को कोष्ठक के भीतर किसी भी डेटा प्रकार के अल्पविराम से अलग किए गए मानों के समूह के रूप में दर्शाया गया है 
p=(1, 2, 3, 4, 5)
q=(2,4,6,8,10)
r=('a', 'b', 'c', 'd', 'e')
Set 
एक set एक परिवर्तनशील डेटा प्रकार है जो सूचियों की तरह बनाया जाता है, लेकिन { } के साथ। यह विभिन्न प्रकार के मान ले सकता है लेकिन इसमें परिवर्तनशील तत्व और डुप्लिकेट प्रविष्टियाँ नहीं हो सकती हैं। 
set1 = {1, 2, 3,4 }
Dictionaries
Dictionary अल्पविराम से अलग की गई कुंजी का एक अव्यवस्थित सेट है: मूल्य जोड़े, जो { }, इस आवश्यकता के साथ कि एक dictionary के भीतर, कोई भी दो कुंजी समान नहीं हो सकती हैं। 
vowels = {'a': 1, 'e': 2, 'i':, 3, 'o': 4, 'u': 5}
>>>vowels ['a'] 
1
fruits = ["apple", "banana", "orange"]
print(fruits)
apple
banana
orange
fruits.append("grape")
print(fruits)
apple
banana
orange
grape
fruits.remove("orange")
print(fruits)
apple
banana
grape
Quiz
Q1 Which of these is not a core data type?
A Lists
B Dictionary
C Tuples
D Class

Q2 What data type is this li = [1, 23, ‘hello’, 1]
A List
B Dictionary
C Tuple
D Array

Q3 Which of the following function convert a string to a float in python?
A int(x [,base])
B long(x [,base] )
C float(x)
D str(x)

Q4 Which Python datatype maintains the order of elements inserted?
A set
B list
C dict
D Both B and C

Code:
age = "21"
print ("age =", int(age))
Ans age=21

Code:
class Number:
    value = 7
    def __int__(self):
        return self.value
data = Number()
print("number =", int(data))
Ans number=7

1 Ans D
2 Ans A
3 Ans C
4 Ans D

--------------------------------------------------------------------------
Assignment
1 Wap to find area of circle area=3.14*r*r
2 Wap to swap two numbers
3 Wap to evaluate y=mx + c
4 Wap to convert temperature from Celsius to Fahrenheit
5 Calculate volume of Cylinder
6 Wap to find average of marks
7 Calculate simple interest
8 Body mass Index program
9 s=ut+0.5 at*t
10 Wap to find distance between 2 points 
 
Q1 Area of Circle area=3.14*r*r
r=int(input('Enter radius ‘))
area=3.14*r*r
print('Area of Circle ', area)

#Q2 Swap of two numbers
a=12
b=15
print('Before Swapping ‘, a, b)
a, b=b, a
print('After Swapping ‘,a , b)

#Q3 WAP to evaluate y=mx + c
m= int(input('Enter the value of m ‘))
x= int(input('Enter the value of x ‘))
c= int(input('Enter the value of c ‘))
y=m*x + c
print(‘Y=‘, y)

#Q4 WAP to convert temperature from Celsius to Fahrenheit
c= int(input('enter the value of Celsious ‘))
f=(0.55*c)+32
print('Farenheight ',f)

#Q5 Calculate Volume of Cylinder
vol=3.14*r*r*h
r=int(input(‘Enter Radius ‘))
h=int(input(‘Enter Height ‘))
vol=3.14*r*r*h
print(‘Volume of Cylinder ‘,vol)

#Q6 WAP to find average of marks
m1=int(input('Enter Mark 1 ‘))
m2=int(input('Enter Mark 2 ‘))
m3=int(input('Enter Mark 3 ‘))
m4=int(input('Enter Mark 4 ‘))
m5=int(input('Enter Mark 5 ‘))
avg=(m1+m2+m3+m4+m5)/5
print('Average Marks of five Subjects is ',avg)

#Q7 Calculate Simple Interest
p=int(input('Enter Principal Amount ‘))
r=int(input('Enter Rate ‘))
t=int(input('Enter Time ‘))
si=(p*r*t)/100
print('Simple Interest ',si,' Rs.')

#Q8 Body Mass Index program
h=float(input('Enter your Height ‘))
w=float(input('enter your weight ‘))
bmi=w/h
print('Body Mass Index ',bmi)

#Q9 s=ut+0.5 at*t
u=float(input('Enter u ‘))
t=float(input('Enter t ‘))
a=float(input('Enter a ‘))
s=u*t + 0.5 *a*t*t
print(‘Result ‘,s)

#Q10 WAP to find distance between 2 points
import math 
def distance (x1, y1, x2, y2): 
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
x1, y1 = 5,4
x2, y2 = 3, 
dist = distance(x1, y1, x2, y2) 
print(f’The distance between the points is:’,{dist})
------------------------------------------------------------
def sum(a , b)
return a + b
a, b = 5,10
s=sum(a, b)
print(“Sum :”,s)
------------------------------------------------------------
def sum(a , b)
return a + b
x = int(input(“Enter the value of a “))
y = int(input(“Enter the value of b “))
s=sum(x, y)
print(“Sum :”,s)
-----------------------------------------------------------
def sum(a , b):
return a + b
def sub(a, b):
return a-b
def multi(a, b):
return a*b
def div(a, b):
return a/b
def moud(a, b):
return a%b
x = int(input(‘Enter the value of a ‘))
y = int(input(‘Enter the value of b ‘))
s1=sum(x, y)
s2=sub(x, y)
s3=multi(x, y)
s4=div(x, y)
s5=moud(x, y)
print(‘Sum :’,s1)
print(‘Subtraction :’,s2)
print(‘Multiplication :’,s3)
print(‘Division :’,s4)
print(‘Module :’,s5)
--------------------------------------------------------
Math Library Functions
ceil returns the smallest number
math.ceil(num)
math.ceil(1.03)=2.0

sqrt returns the square root of number
math.sqrt(num)
math.sqrt(25)=5

exp returns the natural log
math.exp(num)
math.exp(2)

fabs  returns the absolute value
math.fab(num)
math.fab(-1) 
1

floor  returns the largest integer
math.floor(num)
math.floor(1.5)
2.0

pow returns the power of number
math.pow(base,exp)
math.pow(4,2)
16

factorial  returns the factorial on number
math.factorial(num)  
math.factorial(3)
6

Statement Flow Control
Every programming language provides constructs to support sequence, selection and iteration.
1 Compound Statement
Example:
n1=int(input(“Enter first number “))
n2=int(input(“Enter second number “))
if (n1>n2):
print(“First number is larger “,n1)
else:
print(“Second number is larger “,n2)
-----------------------------------------------------------
n=int(input(“Enter any number 0---999“))
if num <0 :
print(“invalid Entry “)
elif num<10:
print(Single Digit Number “)
elif num<100:
print(“Double Digit Number “)
elif num<=999:
print(“Triple Digit Number “)
-------------------------------------------------------------
num = int(input(“Enter any number for –ve +ve and zero “))
if num<0:
print(“Number is Negative “,num)
elif num>0:
print(“Number is Positive “,num)
else:
print(“Number is Zero “,num)
-------------------------------------------------------------
Looping Statement
The for loop
Syntax
for <variable>  in <sequence>
Example
for n in [10,20,30,40,50]:
print(n)
print(n+2,end=‘ ‘)
The range based for loop
Syntax
for val in range(2,20):
print(val)
---------------------------------------------------------------
Q Write a program to print cubes of numbers in the range 10 to 25

for num in range(10,25):
print(‘cube of number ‘,num, end=“ “)
print(‘is ‘,num**3)

Q WAP to print square root of every alternate number in the range 1 to 10.

for n in range(1,10,2):
print(“Square root of “, n,”is”,(n**0.5))

--------------------------------------------------------------------------
for i in range (1,6):    
for j in range (1,i+1):        
print (j,end=' ')    
print()

Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
---------------------------------------------------------------------------
The while loop
A while loop is a conditional loop that will repeat the instructions within itself as long as a conditional remains true.
Syntax
while <logical Expression>:
loop-body
Example
Q WAP that multiplies two integer number without using * operator using repeated addition.

n1= int(input(‘Enter first number ‘))
n2= int(input(‘Enter second number ‘))
pro=0
c=n1
while c>0:
c=c-1
pro=pro + n2
print(‘The product of ‘,n1, ‘and’ ,n2, ‘is ’,pro)
-----------------------------------------------------------
while True:       
try:               
number = int(input("Enter a number: "))                       
if number > 0:                   
print("The number is positive.")                
elif number < 0:                   
print("The number is negative.")                
else:                   
print("The number is zero.")                        
ans = input("Do you want to check another number? (y/n): ").strip().lower()                
if ans != 'y':                        
print("Goodbye!")                        
break        
except ValueError:                
print("Invalid input! Please enter a valid number.")
---------------------------------------------------------------------------
Lambda Function
एक यह python का विषेश प्रकार का function है। ये functions बिना किसी नाम के लिखे जाते है।
Syntax
lambda argument : expression
Function में argument की कितनी भी संख्या हो सकती है लेकिन expression  एक ही होता है।
प्रोग्राम में जहां भी function object की जरुरत होती है lambda function का प्रयोग किया जाता है।
double= lambda n: 2*n
print(double(5))
def add(n):
return lambda a : a * n
double=add(2)
print(double(11))
------------------------------------------------------------------
String in Python
पायथन में स्ट्रिंग्स को दो-तरफ़ा index len (नाम या प्रत्येक स्थान) के साथ, सन्निहित स्थान में अलग-अलग वर्णों के रूप में संग्रहीत किया जाता है 0   1   2  3   4   5
P   Y   T  H  O  N
-6 -5 -4 -3 -2 -1
name=“MLC”
len(name)
3
Traversing a String
str=“MLC”
for ch in str:
print(ch;’~’,end=‘ ‘)
M~L~C~
--------------------------------------------------------------------------
String Operator
1 String Concatenation Operator +
ऑपरेटर + दो ऑपरेंड स्ट्रिंग को जोड़कर एक नई स्ट्रिंग बनाता है
“MLC”+ “ College”
MLC College
2 String Replicate Operator
Ex:
3* “bye!”
bye!bye!bye
3 Membership Operator
>>>”a” in “hai”
True
>>>”jap” in “hai”
False
>>>”jap” in “Japan”
False
-------------------------------------------------------------------------
4 Comparison Operator 
“a”==“a” True
“abc”==“abc”         True
“A” != “a” True
“ABC”==“abc”  False

String Slices
स्ट्रिन स्लाइस शब्द स्ट्रिंग के एक हिस्से को संदर्भित करता है, जहां स्ट्रिंग को सूचकांकों की एक श्रृंखला का उपयोग करके काटा जाता है।
str=“MLC College”
Its count from 0 to 4 and remaining character
str[4:11]
College
str[:3]
MLC 
------------------------------------------------------------------------
String Functions:
<string object>.<method name()>
str=“Hello”
1. str.length() Find the length of string
5
2. str.captalize() First character capitalize
‘i love my India’.capitalize()
I love my India
str=“mlc”
str.capitalize()
Mlc
3. <str>.find(sub[,start[,end]])
स्ट्रिंग में निम्नतम सूचकांक लौटाता है जहां सबस्ट्रिंग उप प्रारंभ और अंत की स्लाइस सीमा के भीतर पाया जाता है।
str=“I like Python”
str1=“Hello”
sub=“e”
sub=“Python”
print (str.find(sub,2,14))
print (str1.find(sub,1,4))
-1
<str>.isalnum()
यदि स्ट्रिंग str में वर्ण अल्फ़ान्यूमेरिक हैं और कम से कम एक वर्ण है, तो सत्य लौटाता है।
string=“abc123”
string.isalnum()
True
string.isalpa()
False
-----------------------------------------------------------------------
string.isdigit()
False
<str>.isspace()
यदि स्ट्रिंग में केवल रिक्त स्थान वर्ण हैं तो सत्य लौटाता है।
string=“  “
string.isspace()
True
str=“Mlc “
<str>.islower()
str.islower()
False
<str>.isupper()
str.isupper()
True
<str>.istitle()
str.istitle()
True
<str>.swapcase()
str.swapcase()
mLC
Replace() method
str1 = "Ram is doing PGDCA, Shayam is doing PGDCA, and Sita is doing PGDCA“
str2 = str1.replace('PGDCA','DCA’) 
print(str2)
Ram is doing DCA, Shayam is doing DCA, and Sita is doing DCA
---------------------------------------------------------------------------
endswith()
s1="Python Programming“
s2="Programming“
s1.endswith(s2)
True
s1="Python Programming“
s2="Programming“
s1.endswith("Python")
False
--------------------------------------------------------------------------
startswith()
s1="Python Programming“
s2="Python“
s1.startswith("Python")
True
------------------------------------------------------------------------
rfind() 
यह मैथड किसी सबस्टिंग की स्टिंग में अंतिम उपस्थिति का इंडेक्स क्रमांक प्रदर्षित करता है।
s1.rfind(s2)
जहां s2 वह सबस्टिं्रग है जिसके s1 में अंतिम उपस्थित का index क्रमांक प्रदर्षित करना है।
s1=‘Python Programming’
print(s1.rfind(“n”))
16
----------------------------------------------------------------------
rstrip()
यह मैथड स्टिंग के दाई ओर के white space को हटाकर स्टिंग को प्रदर्षित करता है।
str.rstrip()
str=“I love India “
print(str.rstrip())
I love India
----------------------------------------------------------------------
lstrip()
यह मैथड स्टिंग के बांयी ओर के white space को हटाकर स्टिंग को प्रदर्षित करता है। 
str.lstrip()
str=“ I love India“
print(str.lstrip())
I love India
----------------------------------------------------------------------
strip()
यह मैथड स्टिंग के द्वारा बांय और दाये white space को हटाकर स्टिंग को प्रदर्षित करता है।
----------------------------------------------------------------------
str.strip()
str=“ I love India “
print(str.lstrip())
“I love India”
---------------------------------------------------------------------
center()
इस मैथड का प्रयोग किसी स्टिंग को दिये गये चैडाई के मध्य में प्रदर्षित करता है। 
str.center(width)
str=‘I love Python’
print(str.center(50))
I love Python

rjust() 
यह मैथड किसी दी हुई चैडाई के अ्रर्तगत एक स्टिंग को left justified कर  प्रदर्षित करता है।  
str.ljust (int width)
country="  India“
print(country.ljust(30))
   India
country="India“
print(country.rjust(30, '*’))
************************India
------------------------------------------------------------------------
split()
इस मैथड की मदद से किसी स्टिंग के प्रत्येक षब्द को सपेज के elements के रुप में प्राप्त किया जाता है।  
str=“I love India”
print(str.split())
['I', 'love', 'Python’]
-------------------------------------------------------------------
WAP to read a line and prints , Number of uppercase letter , Number of lowercase letter, Number of alphabets, Number of Digits
line= input('Enter line ‘)
low=0 upper=0 digit=0 alpha=0
for a in line:    
if a.islower():        
low+=1    
elif a.isupper():        
upper+=1    
elif a.isdigit():        
digit+=1    
alpha=low + upper + digit
print('Number of upper case = ',upper)
print('Number of lower case = ',low)
print('Number of digit= ',digit)
print('Number of alpha = ',alpha)
-------------------------------------------------------------------------
print(f"{'Item':<10}{'Quantity':<10}{'Price':<10}")
print(f"{'Apples':<10}{10:<10}{50:<10.2f}")
print(f"{'Bananas':<10}{20:<10}{25:<10.2f}")
output
Item      Quantity  Price
Apples    10          50
Bananas   20        25

print("Hello", end=" ")
print("World!")

Hello World!
----------------------------------------------------------------------
Q User Registration System
Collect user information
username = input("Enter a username: ")
email = input("Enter your email: ")
password = input("Enter a password: ")
# Save user information to a file
with open('users.txt', 'a') as f:
    f.write(f"Username: {username}\n")
    f.write(f"Email: {email}\n")
    f.write(f"Password: {password}\n")
    f.write("-" * 20 + "\n")
print("User registered successfully!")
Enter a username: Sadhana
Enter your email: sadhanamlc@gmail.com
Enter a password: 12345
User registered successfully!
----------------------------------------------------------------------
List in Python
सूची पायथन का एक मानक डेटा प्रकार है जो किसी भी प्रकार से संबंधित मानों के अनुक्रम को संग्रहीत कर सकता है।
[ ]
[1,2,3]
[ ‘a’, ’b’, ’c’, ’d’, ’e’]
[‘a’, ’b’, 12,1.5,]
[‘one’, ‘two’, ‘three’]
सूचियाँ परिवर्तनशील हैं. आप किसी सूची के तत्वों को उनके स्थान पर बदल सकते हैं। सूची और शब्दकोश परिवर्तनशील (mutable) प्रकार के हैं।
Creating list
L=[ ]
L=list()
Li=list(‘hello’)
Li 
[‘h’,’e’,’l’,’l’,’o’]
Create list from keyboard input
Li=list(input(‘Enter elements :’))
Enter elements:12345
[‘1’,’2’,’3’,’4’,’5’]
सूचियाँ इनपुट करने के लिए सबसे अधिक उपयोग की जाने वाली विधि eval(input()) है
Example
list=eval(input(‘Enter list:’))
print(‘You entered ‘list);
Traversing a list
L=[‘p’,’y’,’t’,’h’,’o’,’n’]
for a in L:
print(a)
p
n
---------------------------------------------------------------------
Joining Lists
Concatenation ऑपरेटर +  सूचियों में शामिल हो सकता है।
list1=[1,2,3]
list2=[4,5,6]
list1+ list2
[1,2,3,4,5,6]
Replicating lists
list1=[1,2,3]
list1*3
[1,2,3,1,2,3,1,2,3]
Slicing the lists
seq=L[start : stop]
lst=[10,12,14,16,18,20]
seq=lst[3 : -3]
[16,18,20]
L= [‘one’,’two’,’three’]
L[0:2=[0,1]
L
[0,1,’three’]
List manipulation append
lst1=[10,12,15]
lst1.append(16)
print(lst1)
[10,12,15,16]
lst1=[10,12,14,16]
lst1[2]=25
print (lst1)
[10,12,25,16]
lst=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
del lst[10:15]
[1,2,3,4,5,6,7,8,9,10,16]
To delete single element use pop()
Making true copy of list
col=[‘red’, ’blue’, ’green’]
c=col
Index method
L1=[1,2,3,4,5,6]
L1.index[5]
4
Append method
col=[‘red’,’blue’,’green’]
col.append(‘yellow’)
print(col)
[‘red’, ’blue’, ’green’, ’yellow’]
Extend List
t1=[‘a’,’b’,’c’]
t2=[‘d’,’e’]
t1.extend(t2)
print(t1)
[‘a’, ’b’, ’c’, ’d’, ’e’]
Append add a elements in a list where as extend add multiple elements in a list.
The insert method
t1=[‘a’, ’e’, ’u’]
t1.insert(2,’i’)
print(t1)
[‘a’,’e’,’i’,’u’]
pop method
t1=[‘k’,’a’,’e’,’i’,’o’,’u’]
t2=t1.pop(0)
print(t2)
k
The remove method
t1=[‘a’,’e’,’i’,’o’’u’]
t1.remove(‘a’)
print(t1)
[‘e’,’i’,’o’,’u’]
clear method
t1=[2,3,4,5]
t1.clear( )
print(t1)
[ ]
count method
t1=[11,12,13,14,15,16,15]
t1.count(15)
2
t1.count(20)
0
The reverse method
lst1=[‘a’,’e’,’i’,’o’,’u’]
lst1.reverse()
print(lst1)
[‘u’,’o’,’i’,’e’,’a’]
sort method
lst1=‘a’,b’,’x’,’e’]
lst1.sort()
print(lst1)
[‘a’,’b’,e’,’x’]
---------------------------------------------------------------------
Tuples in Python
Creating Tuples
T=()
T=(values…)
T=(1)
t1=tuple(‘hello’)
print(t1)
(‘h’,’e’,’l’,’l’,’o’)
Creating tuple from keyboard
t1=tuple(input(‘enter tuple elements ‘))
print(t1)
enter tuple elements:12345
(‘1’,’2’,’3’,’4’,’5’)

tuple=eval(input(‘enter tuple elements :’))
print(‘You entered tuples :’,tuple)
(2,5,7,’a’,”hello”,[1,2])
(2,5,7,’a’,’hello’,[1,2])
Traversing a Tuple
T=(‘p’,’y’,’t’,’h’,’o’,’n’)
for a in T:
print(T[a])
p
y
t
h
o
n
---------------------------------------------------------------
Joining Tuples
T1=(1,2,3)
T2=(4,5,6)
T1+t2
(1,2,3,4,5,6)
Replicating Tuples
T1 * 3
(1,2,3,1,2,3,1,2,3)
Slice the Tuple
seq=t[start : stop]
T1=(10,20,30,40,50,60,70)
seq=t1(3: -3)
print(seq)
40,50,60
Unpacking Tuples
T=(1,2,’a’,’b’)
w,x,y,z=T
print(w,”-”,x,”-”,y,”-”,z,”-”)
1-2-a-b
len()
emp=(‘sita’,10000,25,’sales’)
len(emp)
4
max() 
tp=(10,20,30,40,50,60)
max(tp)
60
min()
tp1=(10,12,34,5,38,30)
min(tp1)
5
index () 
t1=[1,2,3,4,5]
t1.index(4)
3
count () 
t1=(2,4,6,7,9,2,4,7,2,2)
t1.count(2)
4
tuple ()
t=tuple(“abc”)
print(t)
(‘a’,’b’’c’)
-----------------------------------------------------------------
Dictionaries in Python
Creating a Dictionaries
teachers={“Sita” : “Computer”, ”Gita” : “Database”, ”Roma” : “AI”, ”Soma” : “Cloud Computing “}
Each entry (key : value)
Accessing elements of a Dictionary
print(teachers[“Sita”]
Computer 
Accessing keys or values Simultaneously
d={“v1” : “a”, “v2” : “e”, “v3” : “i”, “v4” : “o”, “v5” : “u”}
d.keys()
[“v5”,”v4”,”v3”,”v2”,”v1”]
d.values()
[“u”,”o”,”i“,”e”,”a”]
----------------------------------------------------------------
Characteristics of a Python
एक Dictionary unordered set of key : value pairs. 
स्ट्रिंग, टपल और सूची के विपरीत, एक Dictionary एक अनुक्रम नहीं है। 
Dictionary key अनुक्रमित होते हैं और इसकी key किसी भी (non mutable) गैर-परिवर्तनीय प्रकार की होनी चाहिए। 
Dictionary के भीतर प्रत्येक key unique होनी चाहिए।

Dictionary Operations
Traversing a Dictionary
d1={5:”number”,\“a”:”string”,\(1,2):”tuple”}
for key in d1:
print(key,”:”,d1[key])
a : string
(1,2) : tuple
5 : number

Adding elements to a Dictionary
emp={‘name’ : ‘Sita’, ‘salary’ : 5000, ‘age’ : 25}
emp[‘dept’]=‘marketing’
emp
{‘salary’ : 5000, ‘dept’ : ‘marketing’, ‘age’:25, ,’name’ : ‘Sita’}

Example:
n=int(input(‘How many students ‘))
win=0
for a in range(n):
key=input(‘name of the student ‘)
value=int(input(Number of competition won ‘))
win[key]=value
print(‘The dictionary is :’)
print(win) 

Delete elements from the Dictionary
Dictionary से तत्वों को हटाने की दो विधियाँ हैं।
1 key : value pair
del <dictionay> [key]
>>>emp 
{‘salary’ : 5000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>del emp[‘age’]
>>>emp
{‘salary’ : 5000, ‘name’ : ‘sita’}
2 Another method is by using pop()
<dictionary>.pop(<key>)
>>>emp 
{‘salary’ : 5000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>emp.pop(‘age’)
>>>emp
{‘salary’ : 5000, ‘name’ : ‘sita’}

Checking for existence of a key
Usual membership operators in and out work with dictionary as well. 
<key> in <dictionary>
<key> not in <dictionary>
Example:
>>>emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>’age’ in emp
True
>>>’name’ in emp
True
>>>’age’ not in emp
False

Dictionary Functions and Method
1. len() 
This method returns length of the dictionary 
len <dictionary>
>>>emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
len(emp)
3
2. clear( ) 
This method removes all items from the dictionary and dictionary become empty.
<dictionary>.clear( )
>>>emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
emp.clear( )
>>>emp
{ }
3 The get( )
With this method, you can get the item with the given keys.
<dictionary>.get(key, [default])
>>> emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>emp.get(‘salary’)
10000
4 The items( )
This method returns all the items in the dictionary as a sequence of (key, value) tuples.
<dictionary>.items( )
emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
lst=emp.items( )
for x in lst:
  print(x)
5 The keys( )
This method returns all of the keys in the dictionary as a sequence.
<dictionary>.keys( )
emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>emp.keys()
[‘salary’, ’age’, ‘name’]
6 The values( )
This method returns all of the values in the dictionary as a sequence.
<dictionary>.keys( )
emp={‘salary’ : 10000, ‘age’ : 25, ‘name’ : ‘sita’}
>>>emp.values()
[10000, 25, sita]
7 The update ()
This method merges key : value pair from the new dictionary in the original dictionary, adding or replacing as needed.
<dictionary>.update(<other dictionary>)
emp1={"salary" : 10000, "age" : 25, "name" : "sita"}
emp2={"salary" : 15000, "name" : "sita", "dept" : "sales"}
emp1.update(emp2)
print(emp2)
print(emp1)

{‘salary’: 15000, , ‘name’ : ‘sita’, ‘dept’ : ‘sales’}
{‘salary’ : 15000, ‘age’ : 25, ‘name’ : ‘sita’, ‘dept’ : ‘sales’}
-------------------------------------------------------------------------
Write a program that finds an elements index/position in a tuple without using index()
tuple=(‘c’, ’o’, ’m’, ’p’, ’u’, ’t’, ’e’, ‘r’)
char=input(‘Enter a single letter without quotes :’)
if char in tuple:
count=0
for a in tuple:
if a != char:
else:
break
print(char, ’is at index’, count, ‘in’, tuple)
else:
print(char,’ is not in’ ,tuple)
  
Q WAP that checks for presence of a value inside a dictionary and prints its key.

info={‘Riya’ : ‘CS’, ’Siya’ : ‘Maths’, ‘Gita’ : ‘IT’}
val=input(‘Entered the value to search:’)
if val in info:
for a in info:
if info(a)==val:
print(“The given value is “,a)
break
else:
print(“Given value dose not exist in dictionary “)
Answer
Entered the value to searched CS
Riya
-------------------------------------------------------------------------
Sorting Techniques
ऐसे कई तरीके या तकनीकें हैं जिन्हें आप election sort, insertion sort, bubble sort, heap sort, quick sort.जैसे तत्वों के समूह को सॉर्ट करने के लिए लागू कर सकते हैं।

Example
#bubble sorting
lst=[15,12,14,18,20,5]
print(‘Original List ‘,lst)
n=len(lst)
for i in range(n):
for j in range(0,n-i-1):
if lst[j]>lst[j+1]:
lst[j],lst[j+1]=lst[j+1],lst[j]
print(‘List after sorting ‘,lst)
---------------------------------------------------------------------------
#Insertion sorting
lst=[15,12,14,18,20,5]
print(‘Original List ‘,lst)
for i in range(1,len(lst)):
key=lst[i]
j=i-1
while j>=0 and key<lst[j]:
lst[j+1]=lst[j]
j=j-1
else:
lst[j+1]=key
print(‘List after sorting ‘, lst)
--------------------------------------------------------------------------
Quiz
1 The numbered position of a letter in a string is called….
(a) position (b) integer position (c) index (d) location
2 The operator … tells if an element is present in a sequence or not.
(a) exists (b) in (c) into (d) inside
3 The keys of a dictionary must be of ….. Type
(a) integer (b) mutable (c)immutable (d)any of these
4 Following set of  command is executed in shell, what will be the output.
>>>str=“hello”
>>>str[:2]
>>>
(a) he (b) lo (c) olleh (d) hello
5 What data type is the object below?
L=[1,23,’hello’,1]
(a)list (b) dictionary (c) array (d) tuple
6 What data type is the object below?
L=1,23,’hello’,1
(a) list (b) dictionary (c) array (d) tuple
7 To store values in terms of key and value, what core data type does Python provide?
(a) list (b) tuple (c) class (d) dictionary
8 What is the value of expression?
3+3.00,3*3.0
(a) (6.0,27.0) (b) (6.0,9.00) (c) (6,27) (d) [6.0,27.0]
(e) [6,27]
9 List lst defined as follows:
lst=[1,2,3,4,5]
Which of the following statements remove the middle element 3 from it so that the list lst equals [1,2,4,5]
(a) del a[2] (b) a[2:3]=[ ] (c) a[2:2]=[ ] (d) a[2]=[ ] 
(e) a.remove(3)
10 Which two lines of code are valid strings in Python?
(a) This is a string (b) ‘This is a string’ (c) “This is a string” (d) (This is a string)
11 You  have a following code segment
string1=“my”
string2 =“work”
print(string1+string2)
What is the output of the code?
(a) my work (b) work (c) mywork (d) my
12 You have the following code segment
string1=“my”
string2=“work”
print(string1+string2.upper())
What is the output of the code?
(a) mywork (b) My Work (c) myWORK (d) My Work
13 Which  line of code produces an error?
(a) “one” + “two” (b) 1 + 2   (C) “one” + “2”  (d) ‘1’ +2
14 What is the output of this code ?
>>> int(“3” + “4”)
(a) “7” (b) “34” (c) 34   (d) 24
15 Which line of code will cause an error ?
num=[5,4,3,[2],1]
print(num[0])
print(num[3][0])
print(num[5])
(a) line 3 (b) line 2  (c) line 4 (d) line 1
16 Which is the correct from of declaration of dictionary
(a) day=[1:’Monday’, 2:’Tuesday’, 3:’Wednesday’]
(b) day=[1;’Monday’, 2;’Tuesday’, 3;’Wednesday’]
(c) day=[1,’Monday’, 2,’Tuesday’, 3,’Wednesday’]
(d) day=[1’Monday’, 2’Tuesday’, 3’Wednesday’]
17 identify the valid declaration of L:
L=[‘mon’,’23’,’hello’,’60.5’]
(a) dictionary (b) string (c) tuple (d) list
18 Suppose a tuple T is declared as T=(10,12,43,39), which of the following is incorrect?
(a) print(T(1)) (b) T[2]=-29 (c) print(max(T)) (d) print(len(T))
---------------------------------------------------------------------------
Answer
1 c
2 b
3 c
4 a
5 a
6 d
7 d
8 a
9 a, b, e
10 b, d
11 c
12 c
13 d
14 c
15 c
16 a
17 d
18 b
फ़ंक्शंस के साथ कार्य करना 
फ़ंक्शन एक उपप्रोग्राम है जो डेटा पर कार्य करता है और अक्सर एक मान लौटाता है।
def cal(x):
  r=2 * x **2
return r
a= int(input(“Enter a number “))
print((cal(a))

def का मतलब है कि एक फ़ंक्शन परिभाषा शुरू हो रही है। 
'def' के बाद आने वाला पहचानकर्ता फ़ंक्शन का नाम है, फ़ंक्शन का नाम cal है। 
कोष्ठक के अंदर चर तर्क (x) हैं। 
def लाइन के अंत में एक कोलन : है 
रिटर्न स्टेटमेंट गणना किए गए परिणाम देता है।
-----------------------------------------------------------------------
Example:
class New:    
num=10    
def tot(self,num):        
num=50        
print('value of local num is ',num)        
print('value of instance is ',num)
ob=New()
ob.tot(30)
Answer
value of local num is 50       
value of instance is 50
---------------------------------------------------------------------------
Example:
class New:    
num=10    
def tot(self,num):        
num=50        
print('value of local num is ',num)        print('value of instance is ',self.num)
ob=New()
ob.tot(30)
Answer
value of local num is 50       
value of instance is 10
---------------------------------------------------------------------------
Example:
class master:
def x(self):
print(‘I am in method x’)
def y(self):
print(‘I am in method y’)
self.x()
ob=master()
ob.y()
Answer
I am in method x
I am in method y
-----------------------------------------------------------------------
Python Function Types
1 Built-in functions : 
ये पूर्व-परिभाषित फ़ंक्शन हैं और उपयोग के लिए हमेशा उपलब्ध रहते हैं। 
जैसे len( ), type( ), input( ) 
2 मॉड्यूल में परिभाषित फ़ंक्शन: 
ये फ़ंक्शन विशेष मॉड्यूल में पूर्व-परिभाषित होते हैं और केवल तभी उपयोग किए जा सकते हैं जब संबंधित मॉड्यूल आयात किया जाता है। जैसे कि sin( ), tan( ) 
3 उपयोगकर्ता परिभाषित फ़ंक्शन (UDF) 
प्रोग्रामर के रूप में आप अपने स्वयं के फ़ंक्शन बना सकते हैं। पायथन में फ़ंक्शन को परिभाषित करना 
पायथन में फ़ंक्शन को निम्नलिखित के अनुसार परिभाषित किया गया है:
def sum( x, y):
s=x+ y
return s
--------------------------------------------------------------------------
लाइब्रेरी क्या है 
लाइब्रेरी मॉड्यूल और पैकेजों का एक संग्रह है जो एक साथ एक निर्दिष्ट प्रकार के अनुप्रयोगों या आवश्यकताओं को पूरा करती है। एक लाइब्रेरी में कई मॉड्यूल हो सकते हैं। आमतौर पर उपयोग किए जाने वाले कुछ पायथन लाइब्रेरियाँ नीचे सूचीबद्ध हैं: 
(i) पायथन मानक लाइब्रेरी: (Python Standard Library)
यह लाइब्रेरी पायथन के साथ वितरित है जिसमें विभिन्न प्रकार की कार्यात्मकताओं के लिए मॉड्यूल शामिल हैं। कुछ सामान्य उपयोग किए जाने वाले मॉड्यूल पायथन मानक पुस्तकालय हैं: 
*Mathematical Module, जो विभिन्न प्रकार की गणनाओं का समर्थन करने के लिए गणितीय कार्य प्रदान करता है। 
*cmath Module, जो जटिल संख्याओं के लिए गणितीय कार्य प्रदान करता है।
*Random Module, जो pseudo-random number उत्पन्न करने के लिए कार्य प्रदान करता है। 
*Static Module, जो गणितीय सांख्यिकी प्रदान करता है। 
*Function Urlib Module, जो URL, हैंडलिंग फ़ंक्शंस प्रदान करता है।
(ii) NumPy Library
यह लाइब्रेरी संख्यात्मक सारणी बनाने और हेरफेर करने के लिए उपकरणों के साथ-साथ कुछ उन्नत गणित कार्यात्मकता प्रदान करती है। 
(iii) SciPy Library, 
यह एक और उपयोगी लाइब्रेरी है जो वैज्ञानिक गणनाओं के लिए एल्गोरिदम और गणितीय उपकरण प्रदान करती है। 
(iv) tkinter Library
यह लाइब्रेरी पारंपरिक पायथन उपयोगकर्ता इंटरफ़ेस टूलकिट प्रदान करती है और विभिन्न प्रकार के अनुप्रयोगों के लिए उपयोगकर्ता के अनुकूल GUI इंटरफ़ेस बनाने में मदद करती है। 
(v) Malplotlib Library
यह Library प्लॉट जैसे विभिन्न प्रारूपों में गुणवत्ता आउटपुट का उत्पादन करने के लिए कई फ़ंक्शन और उपकरण प्रदान करती है। चार्ट, ग्राफ़ आदि
मॉड्यूल क्या है 
किसी प्रोग्राम को अलग-अलग घटकों (मॉड्यूल के रूप में जाना जाता है) में विभाजित करने की क्रिया को मॉड्यूलरिटी कहा जाता है। एक मॉड्यूल अपने आप में एक अलग इकाई है। 
यह इसकी जटिलता को कुछ हद तक कम कर देता है और यह कार्यक्रम के भीतर कई अच्छी तरह से परिभाषित, दस्तावेजित सीमाएं बनाता है। 
मॉड्यूल रखने की एक अन्य उपयोगी विशेषता यह है कि इसकी सामग्री को अन्य कार्यक्रमों में पुन: उपयोग किया जा सकता है, उन्हें फिर से लिखने या फिर से बनाने के बिना। 
उदाहरण के लिए, यदि किसी ने एक मॉड्यूल बनाया है, तो अलग-अलग स्रोतों से आने वाले विभिन्न ऑडियो प्रारूपों को चलाने के लिए 'प्ले ऑडियो' कहें। एमपी 3 प्लेयर, एफएम-रेडियो प्लेयर डीवीडी प्लेयर आदि।
पायथन मॉड्यूल की संरचना 
एक पायथन मॉड्यूल में केवल कार्यों के अलावा और भी बहुत कुछ हो सकता है। पायथन मॉड्यूल एक सामान्य पायथन फ़ाइल (.py फ़ाइल) है जिसमें किसी विशेष कार्य से संबंधित निम्नलिखित में से एक या अधिक ऑब्जेक्ट होते हैं: 
*docstring     ट्रिपल quoted टिप्पणियाँ (comments) दस्तावेज़ीकरण उद्देश्य के लिए उपयोगी। 
*डेटा स्थिरांक के लिए चर और लेबल, ऑब्जेक्ट बनाने के लिए 
*क्लास     टेम्प्लेट/ब्लूप्रिंट कुछ वास्तविक या अमूर्त प्रविष्टियों, *अनुदेशों, निर्देशों 
*फ़ंक्शंस के समूह का प्रतिनिधित्व करते हैं। इसलिए हम कह सकते हैं कि मॉड्यूल 'xyz' का अर्थ है कि यह फ़ाइल 'xyz.py' है।
पायथन मॉड्यूल जो पायथन के साथ पहले से लोड होते हैं, मानक लाइब्रेरी मॉड्यूल (Standard Library Module ) कहलाते हैं।
Example 1
def simple(a, b, c):    
return(a*b*c/100)    
num1=int(input("Enter first number "))    
num2=int(input("Enter second number "))   
num3=int(input("Enter third number "))    number=simple(num1,num2,num3)    
print(f“ Simple Interest is {number} ")
Run the program 
<module-name>.<function-name>()
Save this file as si.py then import the file
(ii) Function name is simple with three arguments
>>>import si
>>>si.simple(2000,2,2)
>>>80
----------------------------------------------------------------------
Example 2
def sum(a,b):    
return (a + b)
a, b=5,10
s=sum( a , b)
print("Sum ",s)
--------------------------------------------------------------------
Example 3
def sum(a,b):    
return (a+b)
a=int(input("Enter a "))
b=int(input("Enter b "))
s=sum(a,b)
print("Sum ",s)
-------------------------------------------------------------------
Example 4
def sum(a , b):
return a + b
de f sub(a, b):
return a-b
def multi(a, b):
return a*b
def div(a, b):
return a/b
def moud(a, b):
return a%b
x = int(input('Enter the value of a ‘))
y = int(input('Enter the value of b ‘))
s1=sum(x, y)
s2=sub(x, y)
s3=multi(x, y)
s4=div(x,y)
s5=moud(x,y)
print('Sum :',s1)
print('Subtraction :',s2)
print('Multiplication :',s3)
print('Division :',s4)
print('Module :',s5)
-------------------------------------------------------------------------
Using multiple argument प्रकारों का एक साथ उपयोग करना
Example 5
def interest(principal, time=2, rate=0.10):
return principal * time * rate/100
principal=float(input(“Enter principal amount “)
print(“Simple Interest is :”,si)
si1=interest(principal)
print(“Rs. “,si1)
r=float(input(“Enter rate of interest “)
t=int(input(“Enter time in year “)
print(“Simple Interest =“)
si2=interest(principal, rate, time/100)
print(“Simple Interest “,si2)
---------------------------------------------------------------------------
# Q Convert dollar to Rupees

def convert(dollar):    
rs=dollar*84.44    
return rs
dollar=float(input('Enter Amount in Dollar’))
con=convert(dollar)
print(f"{dollar} Dollar is equal to {con:.2f} Rs.")
print('Rupees is :',convert(dollar))
---------------------------------------------------------------------------
Q WAP to find word character and Alphanumeric percent

str = input("Enter a few sentences: ")
length = len(str)
space = 0
num = 0
for ch in str :    
if ch.isspace() :        
space += 1    
elif ch.isalnum() :        
num += 1
percent = num / length * 100
print("Original Sentences:")
print(str)
print("Number of words =", (space + 1))
print("Number of characters =", length)
print("Alphanumeric Percentage =", percent)
------------------------------------------------------------------------
Q WAP to find which programming language you want to learn

lang = input("What's the programming language you want to learn? ")
match lang:    
case "JavaScript":        
print("You can become a web developer.")    
case "Python":        
print("You can become a Data Scientist")    
case "PHP":        
print("You can become a backend developer")    
case "Solidity":        
print("You can become a Blockchain developer")    
case "Java":        
print("You can become a mobile app developer")    
case _:        
print("The language doesn't matter, what matters is solving problems.")
--------------------------------------------------------------------------
Q WAP to find the letter is vowel or not

def operations(letter):    
switch={       
'a': "It is a vowel",       
'e': "It is a vowel",       
'i': "It is a vowel",       
'o': "It is a vowel",       
'u': "It is a vowel",       
}    
return switch.get(letter,"It is a not a vowel")
letter=input("Enetr any Letter ")
operations(letter)
---------------------------------------------------------------------------
Q Calculator Program

def operations(op, num1, num2):    
match op:        
case '+':            
return num1 + num2        
case '-':            
return num1 - num2        
case '*':            
return num1 * num2        
case '/':            
if num2 != 0:                
return num1 / num2            
else:                
return "Cannot divide by zero"        
case '_':            
return "Invalid operator“
op = input("Enter an operator (+, -, *, /): ")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
result = operations(op, num1, num2)
print("Result:", result)
--------------------------------------------------------------------------
importing Entire Module
Syntax
import module1, module2, module3……
import cal, area
एक मॉड्यूल से चुनिंदा ऑब्जेक्ट आयात करना
यदि आप किसी मॉड्यूल से सभी नहीं, बल्कि कुछ चयनित आइटम आयात करना चाहते हैं, तो आप उपयोग कर सकते हैं
Syntax
from <module> import <objecname> [, objectname> […]*
यदि आप मॉड्यूल से एक भी ऑब्जेक्ट आयात करना चाहते हैं
from math import pi
print(pi)
--------------------------------------------------------------------------
एक पायथन लाइब्रेरी बनाना
ऐसी कुछ लाइब्रेरी हैं Numpy, Scipy, tkinter, आदि।
एक पैकेज एक सामान्य नेमस्पेस के तहत पायथन मॉड्यूल का एक संग्रह है, जो कुछ विशेष फ़ाइलों जैसे _init_.py के साथ एक ही निर्देशिका पर विभिन्न मॉड्यूल रखकर बनाया गया है।
एक लाइब्रेरी में एक या अधिक पैकेज और उपपैकेज हो सकते हैं।पैकेज की संरचना
import sys
print(sys.path)
------------------------------------------------------------------
पायथन पुस्तकालयों का उपयोग/आयात करना
Using/Importing Python Libraries
एक बार जब खुद का पैकेज और सबपैकेज बना लेते हैं और इसे कंप्यूटर पर वर्तमान पायथन इंस्टॉलेशन के साइट-पैकेज फ़ोल्डर में संलग्न कर लेते हैं।
स्थापित पायथन लाइब्रेरी का उपयोग करने के लिए आपको निम्नलिखित कार्य करने होंगे:
1 import command का उपयोग करके Library import करें:
import <full name of library>
लाइब्रेरी में परिभाषित फ़ंक्शन, विशेषता आदि का पूरा नाम देकर उपयोग करें।

Example 1
#details.py
“””Details about computer subjects in CBSE”””
def sublist():
print(“There are two computer subjects is CBSE “)
print(“Computer Science & “Informatics Practices”)

Example 2
#csXI.py
“””Details about CBSE CS XI”””
def syllabus() :
print(“Unit 1 :Programming and Computational Thinking “)
print(“ :Python basics, basic sorting techniques etc.”)
print(“Unit 2 : Computer System and Organisation System “)
print(“ :Computer organisation, execution, cloud computing”)
print(“Unit 3 : Data Management “)
print(“ :SQL, basics of NoSQL database etc.”)
print(“Unit 4 : Society, Law and ethics “)
print(“ :Cyber Safety, safe data communication etc.”)
print(“ Unit 5 :Practical Unit “)
def about():
print(“Computer Science XI”)
print(“Contains 4 units and practical unit “)
जैसा कि जानते हैं कि detail module में एक फ़ंक्शन होता है जिसका नाम sublist( ) है और csXI module में दो फ़ंक्शन हैं अर्थात् syllabus( ) और about ( )
module detail import करने के लिए,  import command इस प्रकार लिख सकते हैं:

import libcompsub.details
यहाँ licompsub एक package है
और इसका पूरा नाम देकर इसके कार्यों का उपयोग करें
libcompsub.details.<function>()
import libcompsub.details
libcompusub.details.sublist()
#Output is:
There are two computer subjects is CBSE
Computer Science & Informatics Practices

(ii) To import module csXI, you can write import command as:
import libcompsub.compscience.csXI
Here csXI module inside compscience subfolder of package libcompsub its full name.
import libcompsub.compscience.csXI.syllabus()
Output is:
Unit 1 :Programming and Computational Thinking 
   :Python basics, basic sorting techniques etc.
Unit 2 : Computer System and Organisation System
:Computer organisation, execution, cloud computing
:SQL, basics of NoSQL database etc.
Unit 4 : Society, Law and ethics 
:Cyber Safety, safe data communication etc.
Unit 5 :Practical Unit 
Example
# module.py
def greet(name):
    return f "Hello, {name}!"
Save this file in folder sample and file name module.py
Run this program in prompt 
import module
sample.module.greet(“Sadhana”)
Output
Hello, Sadhana
-----------------------------------------------------------------
Q1 Write a program having following functions:
def letter1(sentence, letter):
return sentence.replace(letter, '')

# Example usage
sentence = “Wel-Come to MLC!"
letter = "e"
result = letter1(sentence, letter)
print("Original Sentence:", sentence)
print("Modified Sentence:", result)
Output
Original Sentence: Wel-Come to MLC!
Modified Sentence: Wl-Com to MLC
--------------------------------------------------------------
FILE HANDELING
अधिकांश कंप्यूटर प्रोग्राम फाइलों के साथ काम करते हैं। ऐसा इसलिए है क्योंकि फ़ाइलें स्थायी रूप से जानकारी संग्रहीत करने में मदद करती हैं। वर्ड प्रोसेसर दस्तावेज़ फ़ाइलें बनाता है; डेटाबेस प्रोग्राम सूचना की फ़ाइल बनाता है; कंपाइलर स्रोत फ़ाइलें पढ़ते हैं और निष्पादन योग्य फ़ाइलें उत्पन्न करते हैं। तो, हम देख सकते हैं, यह वे फ़ाइलें हैं जिन पर अधिकतर आंतरिक प्रोग्रामों के साथ काम किया जाता है। एक फ़ाइल अपने आप में कुछ स्टोरेज डिवाइस जैसे हार्ड-डिस्क, थंब-ड्राइव आदि पर संग्रहीत बाइट्स का एक समूह है।

डेटा फ़ाइलें 
डेटा फ़ाइलें वह फ़ाइल होती हैं जो किसी विशिष्ट एप्लिकेशन से संबंधित डेटा को बाद में उपयोग के लिए संग्रहीत करती हैं। डेटा फ़ाइलों को दो तरीकों से संग्रहीत किया जा सकता है।
Text File (ii) Binary Files
टेक्स्ट फ़ाइलें
टेक्स्ट ASCII या यूनिकोड वर्णों की एक धारा के रूप में जानकारी संग्रहीत करता है जो प्रोग्रामिंग प्लेटफ़ॉर्म के लिए डिफ़ॉल्ट है। टेक्स्ट फ़ाइलों में टेक्स्ट की प्रत्येक पंक्ति EOL End Of Line  के रूप में  जाने वाले विशेष वर्ण से समाप्त होती है। टेक्स्ट फ़ाइलें निम्न प्रकार की हो सकती हैं
नियमित टेक्स्ट फ़ाइलेंर ये वे फ़ाइलें हैं जो टेक्स्ट को उसी रूप में संग्रहीत करती हैं जैसा कि टाइप किया गया है। 
न्यूलाइन वर्ण एक पंक्ति को समाप्त करता है और टेक्स्ट ट्रांसलेशन होता है। इन फ़ाइलों का फ़ाइल एक्सटेंशन .txt है। 
सीमांकित टेक्स्ट फ़ाइलें ये टेक्स्ट फ़ाइलें हैं जिनमें मानों को अलग करने के लिए एक विशिष्ट वर्ण संग्रहीत किया जाता है।जब संग्रहीत मानों को अलग करने के लिए वर्ण का उपयोग किया जाता है तो इन्हें TSV फ़ाइलें (टैब सेपरेटेड वैल्यूज़ फ़ाइलेंद्) कहा जाता है। ये फ़ाइलें .txt या .csv के रूप में एक्सटेंशन ले सकती हैं।
जब संग्रहीत मानों को अलग करने के लिए अल्पविराम का उपयोग किया जाता है तो इन्हें CSV (Comma Separated Values) फ़ाइलें (अल्पविराम से अलग किए गए मान) कहा जाता है। 
ये फ़ाइलें .csv के रूप में एक्सटेंशन लेती हैं।
TSV (Tab Separated Values)

नियमित टेक्स्ट फ़ाइल : I am simple text
TSV फ़ाइल :  I    am    simple    text.
CSV फ़ाइल: I, am, simple, text,
बाइनरी फ़ाइलें: एक बाइनरी फ़ाइल जानकारी को बाइट्स की एक धारा के रूप में संग्रहीत करती है। एक बाइनरी फ़ाइल में जानकारी उसी प्रारूप में होती है जिसमें वह मेमोरी में संग्रहीत होती है आपको जो फ़ाइल सामग्री लौटाई जाती है वह कच्ची होती है।बाइनरी फ़ाइलें कई एक्सटेंशन ले सकती हैं। अधिकांश गैर.टेक्स्ट फ़ाइल एक्सटेंशन बाइनरी होती हैं।



 

 




 































 

















































 



























































































 

Python Notes

  पायथन क्लास साधना शर्मा द्वारा एमएससी ( आईटी )  एम . फिल ( सीएस )  एमबीए •       To learn Python programming experience is not requ...