Python Soc
Python Soc
A Report submitted in partial fulfillment of the requirements for the award of credits
to a skill-oriented course: Full Stack with Python
Bachelor of Technology
II Year
In
www.kitsguntur.ac.in
October-20
DEPARTMENT OF CSE-ARTIFICIAL INTELLIGENCE & MACHINE LEARNING
KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES
(Approved by A.I.C.T.E New Delhi || Permanently Affiliated to JNTUK, Kakinada) || Accredited with ‘A’ Grade by
NAAC || NBA Accreditation status for 5 B.Tech Programmes (Civil, CSE, ECE, EEE & Mech))
CERTIFICATE
This is to certify that this “Skill Oriented Course of Full Stack with Python” is
done by C. Mohana Venkata Adithya (23JR1A4242) in the duration of 2024
to 2025, who carried out the work under supervision and submitted in the partial
fulfillment of the requirements for the award of the degree of Bachelor of
Technology in Computer Science & Engineering-Artificial Intelligence &
Machine Learning from JNTU-Kakinada.
DECLARATION
We hereby inform that this t “Skill Oriented Course of Full Stack with Python” is
has been carried out by myself in the duration of 2024 to 2025, and submitted in
partial fulfillment for the award to the degree of Bachelor of Technology in
Computer Science and Engineering-Artificial Intelligence & Machine Learning to
Jawaharlal Nehru Technological University Kakinada under the guidance
of Mohammad John Saida, Asst. Prof, Dept. of Computer Science and Engineering-
Artificial Intelligence & Machine Learning.
ACKNOWLEDGEMENT
We would like to express our profound gratitude towards Mohammad John Saida, Asst.Prof,
Department of CSE-AI & ML, who played a supervisory role to utmost perfection for guiding as
an internal guide methodically and meticulously.
We are very much thankful to the college management for their continuous
support and facilities provided.
We render our deep sense of gratitude to Dr. P. BABU, Principal & Dr K Hari Babu,
Academic Director , for permitting us to carry out Skill Oriented course on Full Stack with
Python development. We would like to express our sincere thanks to Computer Science and
Engineering-Artificial Intelligence & Machine Learning staff for lending us their time to help us
and complete the work successfully.We would also like to thank our staff, parents and friends
for their enduring encouragement and assistance whenever required.
INSTITUTION VISION
To produce eminent and ethical Engineers and Managers for society by
imparting quality professional education with emphasis on human values and
holistic excellence.
INSTITUTION MISSION
Department VISION
Department MISSION
• Impart rigorous training to acquire knowledge through the state-of-the-art concepts and
technologies in Artificial Intelligence.
• Inculcate values of professional ethics, social concerns, life-long learning and environment
protection.
7
PYTHON
Python is a high-level, interpreted programming language that is widely used for
various purposes such as web development, scientific computing, data analysis,
artificial intelligence, and more. It's known for its simplicity, readability, and ease of
use, making it a great language for beginners and experts alike.
➢ Less lines of code
➢ No rules
➢ No char,short int,long int,double,long double,sighned,unsighned
➢ No switch,do-while,pointers
➢ No braces for block statements
➢ No need for declaring variable
➢ Dynamic typing language-The data type of the variable is decided at run time
only
Features Of Python
2. Easy to Learn: Python program is clearly defined and easily readable. The
structure of the program is simple. It uses few keywords and clearly defined
syntax.
4. Free and Open Source: It is a Open Source Software. So, anyone can freely
distribute it, read the source code, edit it, and even use the code to write new
(free) programs.
8
5. High-level Language: While writing programs in Python we do not worry
about the low-level details like managing memory used by the program.
simple
Inter-preter
Easy to
learn
Features
of
object
oriented
Python High level
programming language
portable Dynamic
7. Portable: It is a portable language and hence the programs behave the same
on wide variety of hardware platforms with different operating systems.
9
9. Interpreted: Python is processed at runtime by interpreter. So, there is no
need to compile a program before executing it. You can simply run the
program. Basically python converts source program into intermediate form
called byte code.
13.Extensive Libraries: Python has huge set of libraries that is easily portable
across different .
10
Tokens
Data
Literals Identifiers keyWords Operators
Types
❖ Literals:
In programming constants are referred to variables that cannot be Changed.
Note:
For c precision part is 6 decimals.
For java and python precesion part is 15 decimals.
• String literal:
11
Examples of string literals include:
1. 'Hello, World!'
2. "This is a string"
3. 'a' (a single character string)
4. '123' (a string, not a number)
❖ Identifiers:
Identifiers are names given to identify something. This something can be a variable,
function, class, module or other object. For naming any identifier, there are some
basic rules.
Rules of Identifiers:-
1.The first character of an identifier must be an underscore ('_') or a letter (upper or
lowercase).
2.The rest of the identifier name can be underscores ('_'), letters (upper or
lowercase), or digits (0- 9).
3.Identifier names are case-sensitive.
For example, myvar and myVar are not the same.
4.Punctuation characters such as @, $, and % are not allowed within identifiers.
Examples of valid identifier names are sum, __my_var, num1, r, var_20, First,
etc…
Examples of invalid identifier names are 1num, my-var, %check, Basic Sal,
H#R&A, etc…
12
❖ Data types:
The variables can hold values of different type called Data type. They
are classifies into two type:
1.Immutable data type:An immutable data type is a type of data that cannot be
changed or modified once it is created. In other words, its state is immutable, meaning
it cannot be altered after it is initialize.
→ In python int,float,bool,String,tuple are the Immutable data type.
→ In immutable data types, when you change the value of a variable, both the
value and the memory location change.
2.Mutable datatype: Mutable data type means that the value of the data can be
changed (mutated) after it is created.
→ In python list,dict,set are called mutable data type.
→ In mutable data type when we change the value of variable only the value chages
but location not changes.
❖ Keywords:
13
Python Keywords
True , False, None , 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, with, while, yield.
❖ Operators:
1.Arithmetic Operator:
14
A Relational or Comparison operator checks the relationship between two operands. If
the relation is true, it returns 1; if the relation is false, it returns value 0.
3.Bitwise operator:
As the name suggests, bitwise operators perform operations at the bit level.
These operators include bitwise AND, bitwise OR, bitwise XOR, and shift operators.
Bitwise operators expect their operands to be of integers and treat them as a sequence
of bits.
• If a number can be expressed in powers of 2 the binary number is 1
followed by x no.of zeroes.
eg: Let x=9 then 2**9=512 in bits 1000000000
• If a number is expressed 2**x-1 the binary value is x no.of ones. eg:
Let x=9 then 2**x-1 in bits 0111111111
→ If n&n-1= = 0 the n can be expressed in powers of 2 otherwise n can’t be
expressed in powes of 2
15
4.Shift Operators:
Python supports two bitwise shift operators. They are shift left (<<) and shift right
(>>). These operations are used to shift bits to the left or to the right.
Left shift(<<): In left shift we move the bit values by one place towards left
We neglect MSB and add 0 to LSB eg: Let
a=12 i.e 00001100 a<<i =a*(2**i)
If i=1 then a<<1=12*(2**1)=24
⸫ a=00001100 then a<<1 is 00011000 i.e 24
Right shift(>>): In right shift we move bit value by one towards rightside We
neglect LSB and add 0 to MSB.
eg: Let a=12 i.e 00001100 a>>i=a//(a**i)
If i=1 then a>>1=12//(2**1)=6
⸫ a=00001100 then a>>1 is 00000110 i.e 6
5.logical operators:
Logical operators are used to simultaneously evaluate two conditions or expressions
with relational operators.
→ Logical And(and): If the first condition false it does not evaluate the second
condition it directly gives false when the both conditions are true it gives true.
→ Logical OR(or): If one or both conditions are true it gives true.
in: This operator gives true if the searching element is found in the given sequence or
iterable otherwise it gives false.
not in: This operator gives true if the searching element is not found in given sequence
or iterable otherwise it gives true.
16
not is:This operator gives true if both variables not sharing same memory location
otherwise it gives false
8.Assignment Operator:
Assignment operators are used in Python to assign values to variables.
Expression is evaluated and result is stored in LHS i.e variable
Additional/Shortcut assign: += , - = ,*=,/=,//=,**= Multiple
assignment :
Var1,var2,var3...varn=val1,val2,val3...valn
9.Comma operator(,):
Variable separator and value separator
Character Set
17
Example:
print(ord(“a”))
print(chr($))
Output:
97
36
Indentation
Whitespace at the beginning of the line is called indentation. These white spaces or the
indentation are very important in Python.
In a Python program, the leading whitespace including spaces and tabs at the beginning
of the logical line determines the indentation level of that logical line.
Once we keep ‘:’ at the end of selection or loop statement then the body of selection or
loop statement will have tab space as identation.
Comments
These are non executable statements in python it is also used to understand the
program in easier manner.
# - It is the single line comment.
‘‘‘ ’’’ - It is the multi line comment.
Statements
A statement is an instruction that the Python interpreter can execute.
2.Selection Statements:
18
if-else: If the condition is true statement1 is evaluated otherwise else part statement2 is
evaluated.
Syntax:
if condition:
statement1 else:
statement2
Synatx:
if condition1: statement1
elif condition2:
statement2 else:
statement3
LOOP STATEMENTS
Loop is an iterative statement which executes for a particular number of times. while
loop:
syntax:
19
initialization i=1
while condition: while i<=10:
statement print(i)
incr/decr i+=1
else: else:
statement2 print('end of while')
loop variable or control variable the initialized value is checked in the condition, as
long as the condition is True, the body of the loop(statements inside the loop) will be
executed, once the condition is False, else part will be executed.
STRINGS
String represents a group of character's. These are very important because most of
the data that we use in daily life in the form of string
20
Triple quote (‘‘‘ ’’’):These are multi line
➢ Operations:
1.Concatenation(+):Merging of two string
It is homogeneous that means string only concatinate
Example:
committment 3 output1:
mittmentcom output2:
entcommittm Code:
s=’commitment’ k=3
print(s[k: ]+s[ :k])
print(s[-k: ]+s[ :-k])
21
String Functions
len() count() find() index() rfind()
rindex() center() ljust() rjust() zfill()
lstrip() rstrip() strip() split() rsplit()
splitness() format() replace() upper() lower()
casefold() title() capitalize() swapcase() isalpha()
isalnum() isspace() isidentifier() isprintable() isascii()
isupper() islower() istitle() isdigit() isdecimal()
isnumeric() startswith() endswith() max() min()
expandtabs() join() chr() ord() str()
Functions:
count() :It gives the frequency of the specified pattern(either single character or a
string) in the given string.
strvar.count(pattern)
find(): it gives the first occurrence of the specified pattern in the given string.
strvar.find(pattern)
strvar.find(pattern,startIndex)
strvar.find(pattern,startIndex,stopIndex) iffind()
is unsuccessful, it gives -1.
It works from left to right.
index(): it gives the first occurrence of the specified pattern in the given string.
It works from left to right.
ifindex()is unsuccessful, it raises an exception called ValueError.
rfind():it gives the last occurrence of the specified pattern in the given string.
22
strvar.rfind(pattern)
strvar.rfind(pattern,startIndex)
strvar.rfind(pattern,startIndex,stopIndex)
it works from right to left. if rfind() is
unsuccessful, it gives -1.
center(): it aligns the string as center aligned in a larger width, the remaining width
is filled by default with spaces or a given single fillchar.
strvar.center(width)
strvar.center(width,fillchar)
ljust(): it aligns the string as left justified in a larger width, the remaining width is
filled by default with spaces or a given single fillchar.
rjust(): it aligns the string in right justified in a larger width, the remaining width is
filled by default with spaces or a given single fillchar.
23
istrip(): it removes the leading(before the start of the string) spaces or any
specified character in the given string strvar.lstrip() : it removes all spaces
strvar.lstrip(char): it removes all chars
rstrip(): it removes the trailing(after the end of the given string) spaces or any
specified character in the given string.
strvar.rstrip() : it removes all spaces strvar.rstrip(char):
it removes all chars
strip(): it removes both leading and trailing spaces or specific characters from the
given string.
split(): it divides the given string into multiple strings(list of strings) based on the
specified delimiter(by default it is space)
rsplit(): it divides the given string into multiple strings(list of strings) based on the
specified delimiter(by default it is space)
split() Vs rsplit(): when we customize the splittings, then split() works from left to
right and rsplit() works from right to left.
upper():it converts the entire string to uppercase(it does not consider digits or
symbols)
24
format(): it is used to place the existing variable in string.
1. using format():
2. using format specifiers
3. using f-strings
replace(): it replaces by default all the occurrences of the specified pattern with the
new pattern in the given string.
strvar.replace(old,new)
isalpha(): it gives True, if the string contains only alphabet(A_Z a_z), if the string
contains one non alphabet it gives False.
isalnum(): it gives True, if the string contains only either alphabet or digits, if the
string contains atleast one symbol it gives False.
isspace(): it gives True, if the string contains only spaces(all types of spaces), if the
string contains atleast one non space character, it gives False.
isascii(): it gives True, if the string contains characters with valid ASCII
values(0127) otherwise it gives False.
isupper(): it gives True, if the string contains only uppercase letters, if the string
contains atleast one lowercase letter it gives False.
islower(): it gives True, if the string contains only lowercase letters, if the string
contains atleast one uppercase letter, it gives False.
25
istitle(): it gives True, if the string is in titlecase(every words starting letter is only
uppercase), otherwise it gives False.
isdigit():it gives True, if the string contains digits or unicode digits(Ex: '\u00B2'),
otherwise it gives False.
isdecimal():it gives True, if the string contains digits otherwise it gives False.
isnumeric():it gives True, if the string contains digits or unicode digits or other
linguistic digits, otherwise it gives False.
startswith():it gives True, if the string is started with the specified pattern,
otherwise it gives False.
endswith():it gives True, if the string ends with the specified pattern, otherwise it
gives False.
Example:
s='this is a test'
print(s.startswith('thi')
)
print(s.endswith('tst'))
output: True
False
26
LISTS
Method1: p=[]
n=int(input())
for i in range(n):
p.append(int(input())) print(p)
Output:
4
5
1
27
2
3
[5,1,2,3]
Output:
3
1
5
8
[1,5,8]
Code:
n=int(input())
p=list(map(int,input().split()))[:n]
print(p)
Output:
3
123456
[1,2,3]
➢ Operations:
1. concatenation(+)
28
2. repetition(*)
3. indexing([])
4. slicing([::])
List Functions
len() count() index() clear()
copy() append() insert() pop()
remove() sort() sorted() min()
max() sum() reverse() extend()
Functions:
3.index(): it gives the first occurrence of the specified element in the given list. if
the element is not found, it raises an exception called ValueError.
5. copy(): it copies only values from one list to another list(it does not share
location). Example: p=[1,2,3] q=p.copy() print(p,q) Output:
[1,2,3] [1,2,3]
29
7. insert(): one element is inserted at a particular index.
listvar.insert(index,element) if the index specified is more than the len(list) then
insert() will behave like append().
9.remove(): it removes the specified element from the list. if the element is not
available, it raises an exception called ValueError.
TIM SORT(insertion +merge)
12.max(): it gives the element with maximum value. to apply max() elements must
be of same type.
14.sum(): it gives sum(total) of the elements of the list. to apply sum() elements
must be of number type.
Example: p=[1,2,3]
p.append(84) print(p)
p.insert(64387438,666) print(p)
30
p.extend([23,56])
print(p)
Output:
[1,2,3,84]
[1,2,3,84,666]
[1,2,3,84,666,23,56]
TUPLES
➢ It is same like list but tuple is immutable and list is mutable. represented
by ().
➢ Tuples contain multiple objects with diffrent data types.
Example:
Code:
t= (1,2,3) a=(1,’String’,[1,2,3])
print(t) print(a)
Output:
(1,2,3)
(1,’String’,[1,2,3])
• Operations:
1. concatenation
2. repetition
3. indexing
4. slicing
31
Tuple Functions
➢ Tuples are utilized by functions in python when they return multiple values.
DICTIONARY
➢ It is a mutable data type where each element has a pair of objects called Key
and Value separated by a ':'.
➢ where Keys are unique(no duplicates) and immutable(we cannot use list or
dict or set as keys).
➢ values may be immutable or mutable.
➢ Dictionaries does not have any order, because order is decided by hashing
technique, that is the reason dictionary in Python is unordered Dictionary.
➢ How to create a dictionary. d={} d=dict()
➢ Operations:
1. indexing: indexing can be done that too key is the index of the
dictionary.
Dictionary Functions
len() max() min() sum()
clear() copy() sorted() updated()
setdefault() pop() popitem() keys()
values() items() fromkeys() get()
Functions:
32
1.len():it gives the length.
if the key is already available in the dictionary, then setdefault() does nothing.
if the key is not avaialable, then key,value pair will be inserted.
dictvar[key]=value
33
15.fromkeys(): a dictionary will be created with the existing sequence elements as
keys and by default values are None. dictvar.fromkeys(sequence)
dictvar.fromkeys(sequence,value)
16.get(): the value of the particular key will be retrieved. dictvar.get(key): if the key
is not available, it returns None dictvar.get(key,value) : if the key is not available, it
returns the default value specified.
SETS
• Set is a mutable data type where it does not allow duplicates. set is mutable,
but set elements are immutable.
• set in Python is unordered, because order is decided by hash function.
we need to use set when we need to remove duplicates but there is no issue
with the order.
p=set()
• Operations:
1. union
2. intersection
Sets Functions
Functions:
34
4. sum(): it gives sum of keys(keys must be number type)
8.update(): we can insert one or more elements into set at a time(if duplicates
are given it will ignore)
setvar.update({ele1,ele2,...elen})
11.remove(): it removes a specific element from the set. if the element is not
avaiable, it raises KeyError. setvar.remove(element)
12.discard(): it is same as remove() but if the element is not available, it does not
raise any exceptions.
35
FUNCTIONS
• Function is set of statements which has self defined task, which is executed
upon access or call or request.
• Functions are two types:
1.built-in functions(pre-defined functions) factorial(),
gcd(), sqrt(), print()
2.user-defined functions:
NOTE:
The function definition must be placed above the function call and in the same
indentation. specific features of functions in Python: 1. A function can be assigned
to a variable.
2. A function can return multiple values at a time 3.
Nested functions are possible.
4. A function can return another function(it avoids the problem in nested functions)
5. Afunction can be used as an argument to another function.
36
• actual arguments: The arguments which are specified in the calling
function
• formal arguments: The arguments which are specified in the called
function.
The communication between actual and formal arguments is called as parameter
passing mechanism.
Based on actual and formal arguments our functions are categorised into
1.Positional arguments
2.keyword arguments
3.default arguments
4.variable length arguments
5.variable length keyword arguments
Anonymous functions
NOTE: lambda functions are used to implement one liner logics only.
RECURSIVE FUNCTIONS:
When a function calls itself, it is known as Recusion.
37
We need to go for recursive function when we can divide a problem into sub
problems.
OOPS IN PYTHON
1.Class
2.Object
3.Encapsulation
4.Inheritance
5.Polymorphism
6.Methods
7.Constructor
1)Class:
Class is a blue print from which objects are created. Class contains data members to
store information and member functions to operate upon data members. Syntax for
class in python: class classname(super class name):
2)Object:
Object is an instances of a class. It is basically a real world implementation of the
class having all those property values which are define or structured in the class.
Syntax for object creation: object name = classname(parameters)
38
3)Encapuslation:
Acquiring properties from one class to another class, the class which gives
Inheritance is called super class or base class or parent class.
The class which gets inheritance is called sub class or derived or child class.
Types of Inheritance:
1.Single or simple Inheritance
2.Multiple inheritance
3.Hierarchical Inheritance
4.Multi level Inheritance
5.Hybrid or Multipath Inheritance
1.Single or simple Inheritance: One base class and one derived class .
2.Multiple inheritance: One derived class and two or more base classes.
3.Hierarchical Inheritance: One base class and two or more derived classes.
4.Multi level Inheritance: One base class(A), one derived class(B) which in turn
serves as a base class for one more derived(C) class.
5.Hybrid or Multipath Inheritance: Combination of two or more inheritance.
Self: Self is a memory variable, which stores the reference of the current calling
object.
Self is used to:
39
1)To access the class variable or members of the class inside the class.
2)To differentiate class variable and local variable if names are same.
➢ In class, there are two types of variables:
2)Instance variable: The variables created or defined inside the constructor of the
class.
6)Methods:
1)Instance method.
2)Class method.
3)Static method.
Instance method:
class A:
a = 78
b = 89
def disp(self):
self.a += 22
self.b += 12
p = A()
print(p.a, p.b)
p.disp()
print(p.a, p.b)
40
q = A()
print(q.a, q.b)
Class method:
class A:
a = 78
b = 89
@classmethod
def disp(cls):
cls.a += 22
cls.b += 12 p =
A() print(p.a,
p.b) p.disp()
print(p.a, p.b) q
= A() print(q.a,
q.b)
Static method:
static method is same as class method it does not have any default positional
argument called self class method and static method can be called using object of
the class or class name also but not instance methods.
7)Constructor:
Constructor is a special method which is executed when we create object for the
class.
• The rule in java or c++ is constructor name is same as the classname and
there is no return type for constructor.
• In python __init__() is the constructor.
1)Default constructor: The constructor without any arguments other than self.
41
2)Parameterized constructor: The constructor with atleast one parameter other
than self.
NOTE:
i)In python, we cannot define multiple methods with same name (either
constructors also or functions also).
ii)We cannot define multiple constructors in the same class (only one constructor
will be executed).
INHERITANCE
42
1.Simple Inheritance: One super class gives inheritance to one sub class.
Uses of super():
• To access the super class constructor in sub class constructor.
• To access super class member inside the subclass constructor or method.
• To access super class method inside subclass constructor or method.
Super() also differentiates super class variable and class variable if names are same.
Like object is superclass of all classes In java,object in the super class of all classes
in python.
2.Multiple Inheritance: One derived class and two or more base classes.
3.Hierarchical Inheritance: One base class and two or more derived classes.
4.Multi-level Inheritance: One base class(A), one derived class(B) which in turn
serves as a base class for one more derived(C) class.
Method Overriding:
When a super class method’s name is same as the method name in sub class,
irrespective of the parameters subclass method will always override superclass
method.
Operator Overloading:
Allows you to define custom behavior for operators when they are used with
userdefined objects. This means you can extend the meaning of operators beyond
their predefined operational meaning. For example, the + operator can be used to
add two integers, concatenate two strings, or merge two lists.
Operator Overloading
43
Pre-defined method for
Operator
Overloading
+ __add__()
- __sub__()
* __mul__()
/ __truediv__()
// __floordiv__()
% __mod__()
** __pow__()
< __lt()__()
> __gt__()
<= __le__()
>= __ge__()
== __eq__()
!= __ne__()
& __and__()
| __or__()
^ __xor__()
<< __lshift__()
>> __rshift__()
~ __invert__()
+= __iadd()
-= __isub__()
*= __imul__()
44
/= __idiv__()
//= __ifloordiv__()
%= __imod__()
**= __imod__()
&= __iand__()
|= __ior__()
^= __ixor__()
_ __neg__()
Abstract class
An abstract class can be considered as a blueprint for other classes. It allows goes
to create a set of methods that must be created within any child classes built from
the abstract class. A class which contains one or more abstract methods is called an
abstract class, an abstract method is a method that has a declaration but does not
have an implementation while we are designing large functional units we use an
abstract class.
By defining an abstract base class, you can define a common application program
interface for a set of subclasses.
45
Patterns programs in Python
1) Write a python program to print the given pattern.
*****
*****
*****
*****
*****
Code:
for x in range(1,6):
for y in range(1,6):
print(“*”, ends=””) print()
Code:
for x in range(1,6):
for y in range(1,6):
print(x,ends=””) print()
46
Code:
for x in range(1,6):
for y in range(1,6):
print(y, ends=””) print()
Code:
for x in range(1,6):
for y in range(65,70):
print(chr(y),ends=””) print()
Code:
47
55555
44444
33333
22222
11111
Code:
for x in range(5,0,-1):
for y in range(5,0,-1):
Print(x,ends=””)
Print()
EEEEE
DDDD
CCCC
BBBBB
AAAAA
Code:
for x in range(69,64,-1):
for y in range(1,6):
Print(chr(x),ends=””)
Print()
48
for x in range(5,0,-1):
for y in range(5,0,-1):
Print(x,ends=””)
Print()
49