Notes
Notes
In [1]:
1 print("Hello")
Hello
Comments:
'''Python is awesome language phython has simple syntax'''
Variables:
In [9]:
1 A = 10
2 print(A)
10
In [12]:
1 A = "Python"
2 print(A)
Python
In [13]:
1 A = 10.1
2 print(A)
10.1
In [14]:
1 A = True
2 print(A)
True
In [17]:
1 A, B, C = 10, 20, 30
2 print(A,B,C)
3 print(B)
4 print(C)
10 20 30
20
30
In [3]:
1 A = 1,2,3,4
2 a,b,c,d = A
3 print(a)
4 print(b)
5 print(c)
6 print(d)
1
2
3
4
In [23]:
1 # USER INPUT
In [4]:
My name is : Anchal
In [30]:
1 # TASK:
In [6]:
Name: Anchal
Contact No 1234567890
Email [email protected]
Address Mohali
Technology Python
In [2]:
1 # Emojis in python:
In [5]:
1 A = "😊😊😊😊"
2 print(A)
😊😊😊😊
1. Employee Name
2. Employee Salary
3. Employee Designation
4. Employee Department
STRINGS:
In [3]:
1 A = "python is awesome"
2 B = A.title()
3 print(B)
Python Is Awesome
In [4]:
1 A = "PYTHON is awesome"
2 B = A.capitalize()
3 print(B)
Python is awesome
OPERATORS
1. Arithmetic
2. Comparison
3. Logical
4. Assignment
5. Membership
Airthmetic Operator:
In [3]:
1 # Addition:
2
3 A = 10
4 B = 10
5 C = A + B
6 print("Sum is :",C)
Sum is : 20
In [4]:
1 # Subtraction:
2
3 A = 10
4 B = 10
5 C = A - B
6 print(C)
In [5]:
1 # Multiplication:
2
3 A = 10
4 B = 10
5 C = A * B
6 print(C)
100
In [7]:
1 # Division:
2
3 A = 11
4 B = 5
5 C = A / B
6 print(C)
2.2
In [8]:
1 # Floor Division:
2
3 A = 11
4 B = 5
5 C = A // B
6 print(C)
In [13]:
1 # Exponentation:
2
3 A = 10
4 B = 3
5 print(A ** B)
1000
In [15]:
1 # Modulas
2
3 A = 11
4 B = 5
5 C = A % B
6 print(C)
In [17]:
10
COMPARISON OPERATOR
1. Greater than
2. Less tham
3. Equal too
4. Not equal too
5. Greater than or equal too
6. Less than or euqal too
In [18]:
1 # Greater Than:
2
3 A = 20
4 B = 10
5 print(A > B)
True
In [19]:
1 # Less than
2
3 A = 10
4 B = 20
5 print(A < B)
True
In [20]:
1 # Equals too:
2
3 A = 10
4 B = 10
5 print(A == B)
True
In [21]:
True
In [25]:
True
In [27]:
True
In [28]:
1 # ASSIGNMENT OPERATORS:
In [29]:
1 A = 10
2 print(A)
10
In [30]:
1 A = 10
2 A += 5
3 print(A)
15
In [31]:
1 A = 10
2 A -= 5
3 print(A)
In [32]:
1 A = 10
2 A /= 5
3 print(A)
2.0
In [34]:
1 A = 10
2 A //= 5
3 print(A)
In [35]:
1 A = 10
2 A *= 5
3 print(A)
50
In [36]:
1 A = 10
2 A **= 5
3 print(A)
100000
Logical operators:
1. AND
2. OR
3. NOT
In [40]:
1 A = 10
2 print(A > 5 and A == 10)
True
In [41]:
1 # OR:
2
3 A = 20
4 print(A == 10 or A == 20)
True
In [43]:
1 # Not
2
3 A = 10
4 print(not(A < 5 and A == 10))
True
Membership:
1. IN
2. NOT IN
In [46]:
1 A = 1,2,3,4,5
2 print(3 in A)
True
In [48]:
1 A = 1,2,3,4,5
2 print(13 not in A)
True
In [ ]:
In [1]:
1 # LIST:
In [3]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number)
3 print(type(number))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
<class 'list'>
In [4]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number[5])
In [5]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number[0:])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In [6]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number[:11])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In [7]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number[::2])
[1, 3, 5, 7, 9]
In [8]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 print(number[-1:-11:-2])
[10, 8, 6, 4, 2]
In [9]:
1 # LIST FUNCTIONS:
In [10]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 number.append(11)
3 print(number)
In [11]:
1 A = [1,2,3,4]
2 B = [5,6,7,8]
3 A.extend(B)
4 print(A)
[1, 2, 3, 4, 5, 6, 7, 8]
In [13]:
1 # Insert:
2 number = [1,2,3,4,5,6,7,8,9,10]
3 number.insert(0,0)
4 print(number)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In [14]:
1 # Remove:
In [15]:
1 number = [1,2,3,4,5,6,7,8,9,10]
2 number.remove(10)
3 print(number)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
In [16]:
1 # Pop:
2
3 number = [1,2,3,4,5,6,7,8,9,10]
4 number.pop(0)
5 print(number)
[2, 3, 4, 5, 6, 7, 8, 9, 10]
In [17]:
1 # Pop:
2
3 number = [1,2,3,4,5,6,7,8,9,10]
4 number.pop()
5 print(number)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
In [18]:
1 # clear:
2
3 number = [1,2,3,4,5,6,7,8,9,10]
4 number.clear()
5 print(number)
[]
In [20]:
1 # del
2
3 number = [1,2,3,4,5,6,7,8,9,10]
4 del number
5 # print(number)
In [21]:
1 # Copy:
2
3 number = [1,2,3,4,5,6,7,8,9,10]
4 A = number.copy()
5 print(number)
6 print(A)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In [22]:
1 A = [1,2,3,4]
2 B = [5,6,7,8]
3 C = A + B
4 print(C)
[1, 2, 3, 4, 5, 6, 7, 8]
In [1]:
1 # TUPLES:
In [3]:
In [4]:
--------------------------------------------------------------------------
-
AttributeError Traceback (most recent call las
t)
~\AppData\Local\Temp\ipykernel_27536\3198605891.py in <module>
1 fruits = ("Apple", "Mango", "Banana", "Orange", "Pear")
----> 2 fruits.append("Strawberry")
3 print(fruits)
In [7]:
In [8]:
1 # Practice Questions:
Dictionary:
In [20]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6
7 print(student)
8 print(type(student))
In [ ]:
1 # Get:
In [3]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6
7 print(student["Name"])
Isha
In [5]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 A = student.get("Rollno")
7 print(A)
101
In [6]:
1 # Keys():
In [7]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 A = student.keys()
7 print(A)
In [8]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 A = student.values()
7 print(A)
In [9]:
1 # Update:
In [10]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student["Name"] = "Anchal"
7 print(student)
In [11]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student["Email"] = "[email protected]"
7 print(student)
In [13]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student.update({"Name" : "Anchal"})
7 print(student)
In [14]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student.update({"Address" : "Mohali"})
7 print(student)
In [15]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student.pop("Name")
7 print(student)
In [17]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student.popitem()
7 print(student)
In [18]:
1 # clear:
In [19]:
1 student = {
2 "Name" : "Isha",
3 "Rollno" : 101,
4 "Tech" : "python"
5 }
6 student.clear()
7 print(student)
{}
In [26]:
1 A = [1,2,4,5,76,97,9,43,3,34]
2 A.sort(reverse = True)
3 print(A)
In [32]:
1 a = "python"
2 print(a[-1:-7:-1])
nohtyp
SETS:
localhost:8888/notebooks/Python Batch 1 (10 to 12).ipynb 16/32
9/15/23, 2:23 PM Python Batch 1 (10 to 12) - Jupyter Notebook
In [2]:
1 A = {1,2,3,5,65,76,3,45,5,3}
2 print(A)
In [3]:
1 # Add:
In [5]:
1 A = {1,3,35,46,57,97,3,4,"isha"}
2 A.add("Anchal")
3 print(A)
In [9]:
1 A = {1,3,35,46,57,97,3,4,"isha"}
2 A.pop()
3 print(A)
In [13]:
1 A = {1,2,3,43,54,45}
2 B = {23,34,35,45}
3 C = A.union(B)
4 print(C)
In [14]:
1 A = {1,3,35,46,57,97,3,4,"isha"}
2 A.clear()A = {1,2,3,43,54,45}
3 B = {23,34,35,45}
4 C = A.union(B)
5 print(C)
6 print(A)
set()
In [17]:
1 A = {1,2,3,43,54,45}
2 B = {23,34,35,45}
3 C = A.intersection(B)
4 print(C)
{45}
Conditional Statements:
1. if
2. if else
3. elif
4. Nested if
In [20]:
1 A = 10
2 if A < 5:
3 print("Sucess")
In [21]:
1 # if else:
In [23]:
1 A = 10
2 if A < 5:
3 print("Hello")
4 else:
5 print("By")
By
In [24]:
In [26]:
In [27]:
1 # elif:
In [30]:
1 A = 10
2 if A < 6:
3 print("hello")
4 elif A < 10:
5 print("hy")
6 elif A < 6:
7 print('By')
8 else:
9 print("Good Bye")
Good Bye
FOR LOOP:
In [3]:
1 A = [1,2,3,4,5,6]
2 for i in A:
3 print(i)
1
2
3
4
5
6
In [4]:
1 A = (1,2,3,4,6,7)
2 for j in A:
3 print(j)
1
2
3
4
6
7
In [5]:
1 # Range()
In [8]:
1 for i in range(10):
2 print(i)
0
1
2
3
4
5
6
7
8
9
In [13]:
1 for i in range(2,20,2):
2 print(i)
2
4
6
8
10
12
14
16
18
In [14]:
In [15]:
0 0
0 1
0 2
0 3
0 4
1 0
1 1
1 2
1 3
1 4
2 0
2 1
2 2
2 3
2 4
3 0
3 1
3 2
3 3
3 4
4 0
4 1
4 2
4 3
4 4
In [16]:
1 *
2 **
3 ***
4 ****
5 *****
File "C:\Users\mitta\AppData\Local\Temp\ipykernel_4220\4239558033.py", l
ine 1
*
^
SyntaxError: invalid syntax
In [20]:
1 for i in range(5):
2 for j in range(5):
3 if i >= j:
4 print("*", end = '')
5 else:
6 print(" ", end = '')
7 print(" ")
*
**
***
****
*****
FUNCTIONS:
Function is a block of code which only runs when it is called
In [4]:
My name is Isha.
My name is Isha.
PARAMETERS:
In [10]:
1 def employee(name,project):
2 print("My name is",name)
3 print("I am working on",project,"project.")
4 employee("Anchal", "NLP")
5 print(" ")
6 employee("Priyanka", "BCPH")
My name is Anchal
I am working on NLP project.
My name is Priyanka
I am working on BCPH project.
In [11]:
In [15]:
1 def student(*name):
2 print("Tooper of the class is",name[3])
3 print("Topper of the class is",name[2])
4 student("Isha", "Anmol", "Kunal", "Sushil")
5 # print(" ")
6 # student("Isha", "Anmol", "Kunal", "Sushil")
In [16]:
1 # KEYWORD ARGUMENTS:
In [17]:
1 def employee(name,project,email):
2 print("My name is",name)
3 print("I am working on",project,"project.")
4 print("My mail is",email)
5 employee(name = "Anchal", project = "NLP", email = "[email protected]")
My name is Anchal
I am working on NLP project.
My mail is [email protected]
In [18]:
In [22]:
I am from Canada
I am from India
In [23]:
1 # Pass Statement:
In [25]:
1 def student():
2 pass
3 student()
In [26]:
1 # RETURN STATEMENT:
In [29]:
1 def add(a):
2 return 5 * a
3 print(add(5))
4 print(add(6))
25
30
1 # OOPS:
In [2]:
1 # CLASS:
In [5]:
1 class Employee:
2 def __init__(self,Name,Project):
3 self.Name = Name
4 self.Project = Project
5 def result(self):
6 print(self.Name)
7 print(self.Project)
8 emp = Employee("Anchal", "BCPH")
9 emp.result()
Anchal
BCPH
In [7]:
1 class Student:
2
3 def details(self,Name, Address):
4 print("My name is",Name)
5 print("I lives in",Address)
6 st = Student()
7 st.details("Anchal", "Mohali")
My name is Anchal
I lives in Mohali
INHERITANCE:
1. Single
2. Multiple
3. Multilevel
4. Hierarchical
5. Hybrid
In [1]:
1 class parent:
2 def pinfo(self, name):
3 print("My name is",name)
4 class child(parent):
5 def cinfo(self, hobby):
6 print("My hobby is",hobby)
7 ch = child()
8 ch.pinfo("ABC")
9 ch.cinfo("playing guitar")
My name is ABC
My hobby is playing guitar
In [2]:
1 # MULTIPLE:
In [3]:
1 class father:
2 def finfo(self,name):
3 print("My name is",name)
4 class mother:
5 def minfo(self, cooking):
6 print("I love to cook",cooking)
7 class child(father,mother):
8 def cinfo(self, study):
9 print("I have done",study)
10 ch = child()
11 ch.finfo("Anchal")
12 ch.minfo("Indian Food")
13 ch.cinfo("M.Tech")
My name is Anchal
I love to cook Indian Food
I have done M.Tech
In [4]:
1 # MULTILEVEL:
In [5]:
1 class grandfather:
2 def ginfo(self,name):
3 print("My name is",name)
4 class father(grandfather):
5 def finfo(self, cooking):
6 print("I love to cook",cooking)
7 class child(father):
8 def cinfo(self, study):
9 print("I have done",study)
10 ch = child()
11 ch.ginfo("Anchal")
12 ch.finfo("Indian Food")
13 ch.cinfo("M.Tech")
My name is Anchal
I love to cook Indian Food
I have done M.Tech
In [6]:
1 # Hierarchical:
In [8]:
1 class parent:
2 def pinfo(self, Name, Hair_color):
3 print("My name is", Name)
4 print("My hair color is",Hair_color)
5 class Child1(parent):
6 def ch1(self, hobby):
7 print("My hobby is",hobby)
8 class Child2(parent):
9 def ch2(self, study):
10 print("I have done",study)
11 c1 = Child1()
12 c1.pinfo("ABC", "Black")
13 c1.ch1("reading books")
14 print(" ")
15 c2 = Child2()
16 c2.pinfo("XYZ", "Black")
17 c2.ch2("MCA")
My name is ABC
My hair color is Black
My hobby is reading books
My name is XYZ
My hair color is Black
I have done MCA
In [9]:
1 # HYBRID:
In [10]:
1 class vehicle:
2 def vinfo(self):
3 print("THIS IS VEHICLE CLASS")
4 class car(vehicle):
5 def cinfo(self):
6 print("THIS IS CAR CLASS")
7 class truck(vehicle):
8 def tinfo(self):
9 print("THIS IS TRUCK CLASS")
10 class sportscar(car,vehicle):
11 def sinfo(self):
12 print("THIS IS SPORTS CAR CLASS")
13 sc = sportscar()
14 sc.vinfo()
15 sc.cinfo()
16 sc.sinfo()
ENCAPSULATION:
Encapsulation is the process of bundling of data members and methods into a single unit.
In [1]:
1 class Employee:
2 def __init__(self, name, project):
3 self.name = name
4 self.project = project
5 def show(self):
6 print(self.name)
7 print(self.project)
8 em = Employee("ABC", "XYZ")
9 em.show()
ABC
XYZ
ACCESS MODIFIERS:
1. Public
2. Private
3. Protected
In [2]:
1 # Public:
In [6]:
1 class employee:
2 def __init__(self, name, address):
3 self.name = name
4 self.address = address
5 def show(self):
6 print("Name:",self.name)
7 print("Address:",self.address)
8 emp = employee("Anchal", "Mohali")
9 emp.show()
10 print(" ")
11 print("Name:", emp.name)
12 print("Address:", emp.address)
Name: Anchal
Address: Mohali
Name: Anchal
Address: Mohali
In [7]:
1 # PRIVATE:
In [5]:
1 class employee:
2 def __init__(self, __name, address):
3 self.__name = __name
4 self.address = address
5 def show(self):
6 print("Name:",self.__name)
7 print("Address:",self.address)
8 emp = employee("Anchal", "Mohali")
9 emp.show()
10 # NAME MAGLING
11 print("Private member is accessed outside the class:")
12 print("Name:", emp._employee__name)
Name: Anchal
Address: Mohali
Private member is accessed outside the class:
Name: Anchal
In [6]:
1 # PROTECTED MEMBERS:
In [9]:
1 class Company:
2 def __init__(self):
3 self._project = "BCPH"
4 class Employee(Company):
5 def __init__(self, name):
6 self.name = name
7 Company.__init__(self)
8 def show(self):
9 print("Name:",self.name)
10 print("Project:", self._project)
11 emp = Employee("Anchal")
12 emp.show()
13
14 print(" ")
15 print("Project:", emp._project)
Name: Anchal
Project: BCPH
Project: BCPH
POLYMORPHISM
In [10]:
1 A = 1,2,3,4,5
2 print(len(A))
In [11]:
1 A = [1,2,3,3,4,5]
2 print(len(A))
In [15]:
1 class Vehicle:
2 def __init__(self, name, color):
3 self.name = name
4 self.color = color
5 def show(self):
6 print("Vehicle name is",self.name)
7 print("It's color is",self.color)
8
9 def max_speed(self):
10 print("Maximum speed of a vehicle is 220")
11 class Car(Vehicle):
12 def max_speed(self):
13 print("Maximum speed of a car is 420")
14 c = Car("Scorpio", "Black")
15 c.show()
16 c.max_speed()
17 print(" ")
18 v = Vehicle("Bike", "Black")
19 v.show()
20 v.max_speed()
TKINTER:
In [*]:
In [ ]:
1 # SIGN UP PAGE:
2 1. First_Name
3 2. Last_Name
4 3. Username
5 4. Password
6 5. Confirm_Passwordwww4eee
7 6. Email
8 7. Contact_No