[go: up one dir, main page]

0% found this document useful (0 votes)
122 views45 pages

Skilldzire Python Document

This document is an internship report submitted by Perumalla Harini for the Full Stack Python project as part of the Bachelor of Technology in Computer Science and Engineering at Raghu Engineering College. It includes sections on Python's introduction, features, applications, installation, requirements, and key concepts, along with acknowledgments and certifications. The report is guided by Mr. M Y V Nagesh and aims to fulfill the requirements for the degree awarded by Jawaharlal Nehru Technological University, Gurajada Vizianagaram.

Uploaded by

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

Skilldzire Python Document

This document is an internship report submitted by Perumalla Harini for the Full Stack Python project as part of the Bachelor of Technology in Computer Science and Engineering at Raghu Engineering College. It includes sections on Python's introduction, features, applications, installation, requirements, and key concepts, along with acknowledgments and certifications. The report is guided by Mr. M Y V Nagesh and aims to fulfill the requirements for the degree awarded by Jawaharlal Nehru Technological University, Gurajada Vizianagaram.

Uploaded by

22981a4248
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

SKILL DZIR E lOM oARcPSD| 45929297

SKILL DZIRE
FULL STACK PYTHON
A Internship Report Submitted at the end of eight semester

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
(INTERNET OF THINGS)

Submitted By
PERUMALLA HARINI
(21981a4943)

Under the esteemed guidance of


SkillDzire
&
Mr. M Y V Nagesh
(Associate Professor)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


(INTERNET OF THINGS)

RAGHU ENGINEERING COLLEGE


(AUTONOMOUS)

Affiliated to JNTU GURAJADA,VIZIANAGARAM


Approved by AICTE, Accredited by NBA, Accredited by NAAC with A+ Grade
www.raghuenggcollege.com
2024-2025

1
lOMoAR cPSD| 45929297

RAGHU ENGINEERING COLLEGE


(AUTONOMOUS)

Affiliated to JNTU GURAJADA,VIZIANAGARAM


Approved by AICTE, Accredited by NBA, Accredited by
NAAC with A+ grade
www.raghuenggcollege.com

2024-2025

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


(INTERNET OF THINGS)

CERTIFICATE

This is to certify that this project entitled “Full Stack Python” done by
“PERUMALLA HARINI (21981A4943)” is a student of B.Tech in the Department of
Computer Science and Engineering, Raghu Engineering College, during the period 2021-
2025, in partial fulfillment for the award of the Degree of Bachelor of Technology in
Computer Science and Engineering to the Jawaharlal Nehru Technological University,
Gurajada Vizianagaram is a record of bonafide work carried out under my guidance and
supervision.

The results embodied in this internship report have not been submitted to any other
University or Institute for the award of any Degree.

Internal Guide Head of the Department

Mr.M Y V Nagesh, Dr.R.Sivaranjani,


Dept of CSE, Dept of CSE,
Raghu Engineering College Raghu Engineering College

Dakamarri (V), Dakamarri (V),

Visakhapatnam. Visakhapatnam.
EXTERNAL EXAMINER

2
lOMoAR cPSD| 45929297

DISSERTATION APPROVAL SHEET


This is to certify that the dissertation

SkillDzire

BY
PERUMALLA HARINI (21981A4943)

Is approved for the degree of Bachelor of Technology

PROJECT GUIDE

Designation

Internal Examiner

External Examiner

HOD

Date:

3
lOMoAR cPSD| 45929297

DECLARATION

This is to certify that this internship titled “Full Stack Python” is bonafied work done by
my me, impartial fulfillment of the requirements for the award of the degree B.Tech
andsubmitted to the Department of Computer Science and Engineering(IOT), Raghu
Engineering College, Dakamarri.

I also declare that this internship is a result of my own effort and that has not been
copied from anyone and I have taken only citations from the sources which are
mentioned in the references.

This work was not submitted earlier at any other University or Institute for the
reward of any degree.

Date:
Place:

PERUMALLA HARINI

(21981A4943)

4
lOMoAR cPSD| 45929297

CERTIFICATE

5
lOMoAR cPSD| 45929297

ACKNOWLEDGEMENT

I express sincere gratitude to my esteemed Institute “Raghu Engineering


College”,which has provided us an opportunity to fulfill the most cherished desire to
reach my goal.
I take this opportunity with great pleasure to put on record our ineffable personal
indebtedness to Mr. Raghu Kalidindi, Chairman of Raghu Engineering
College for providing necessary departmental facilities.
I would like to thank the Principal Dr. CH. Srinivasu of “Raghu Engineering
College”, for providing the requisite facilities to carry out projects on campus.
Your expertise in the subject matter and dedication towards our project have been
a source of inspiration for all of us.
I sincerely express our deep sense of gratitude to Dr.R.Sivaranjani, Professor,
Head of Department Department of Computer Science and Engineering, Raghu
Engineering College, for her perspicacity, wisdom and sagacity coupled with
compassion and patience. It is my great pleasure to submit this work under her
wing. I thank for guiding us for the successful completion of this project work.
I would like to thank Mr. Srikanth Muppalla, SkillDzire for providing the
technical guidance to carry out module assigned. Your expertise in the subject
matter and dedication towards our project have been a source of inspiration for all
of us.
I extend my deep hearted thanks to all faculty members of the Computer Science
department for their value based imparting of theory and practical subjects, which
were used in the project. I thank the non-teaching staff of the Department of
Computer Science and Engineering , Raghu Engineering College, for their
inexpressible support.

Regards
PERUMALLA HARINI
(21981a4943)
.

6
lOMoAR cPSD| 45929297

TABLE OF CONTENTS
CONTENTS PAGE NO.

1. Introduction to Python 9-15

1.1 Introduction 9
1.2 History 9
1.3 Features 9
1.4 Applications 10-11
1.5 Installation of Python 11-12

1.6 Requirements of Python 12-14


1.7 Understanding the execution of Python 14-15

2. Key Concepts 16-23

2.1 Literal Constants 16-17


2.2 Variables and Identifiers 17

2.3 Data Types 17-20


2.4 Operators 20-23
2.5 Type casting vs Type coercion 23

3. Control Statements 24-30

4. Functions 31-38

4.1 Need for Functions 31


4.2 Built -in math- Functions 31-32
4.3 Function aspects 32-33

5. Files and Data Structures 34-37

5.1 Python file handling operations 36-37

7
lOMoAR cPSD| 45929297

6. Structured query language 38-44


6.1 Introduction 38
6.2 Importance of sql 38-39
6.3 Types of Data 39
6.4 Data Types 39-40
6.5 Installation of sql 41
6.6 Creation of tables, databases, inserting values 41- 42
6.7 Select, Where, Projection and Selection 42
6.8 Case Sensitivity 42
6.9 Operators 43-44

7. CONCLUSION 45

8
lOMoAR cPSD| 45929297

1. INTRODUCTION TO PYTHON

1.1 INTRODUCTION
Python is a simple, general purpose, high level, and object-oriented programming
language.
Python is a interpreted scripting language.
Python is a trending programming language to develop various applications.
As of 2022, Python continues to be one of the most popular programming languages
worldwide, used extensively in Web development, data science, machine learning,
artificial intelligence, science computing, automation, and more.
The Python Software Foundation (PSF) oversees Python’s development and promotes its
adoption and growth.

1.2 HISTORY
Invented in Netherlands early by Guido Van Rossum.
Python was conceived in late 1980’s and its implementation was started in December
1989.
Guido van Rossum is fan of ‘Monty Python Firing Circus,’ this is a famous TV show in
Netherlands.
Maned after Monty Python.
Open sourced in the year 2012.
Its vibrant community and thriving ecosystem ensure that Python remains relevant and
continues to evolve to meet the needs of developers and industries alike.

1.3 FEATURES
Easy-to-learn – Python has few keywords, simple structures, and a clearly defined
syntax. This allows the student to pick up the language quickly.
Easy-to-read – Python code is more clearly defined and visible to eyes.
Easy-to-maintain – Python’s source code is fairly easy-to-maintain.
A broad standard library – Python’s bulk pf the library is very portable and
crossplatform compatible on UNIX, Windows, and Macintosh.

Interactive Mode – Python has support for an interactive mode which allows interactive
testing and debugging of snippets of code.

9
lOMoAR cPSD| 45929297

Portable – Python can run on a widely variety of hardware platforms and has the same
interface on all platforms.
Extendable – It can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
Databases – Python provides interfaces to all major commercial databases.
GUI Programming – Python supports GUI applications that can be created and ported
to many system calls, libraries, and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
Scalable – Python provides a better structure and support for large programs than shell
scripting.

1.4 APPLICATIONS

Web Development
• Django – A high-level Python web framework that enables rapid development and
clean, pragmatic design.
• Flask – A lightweight web framework that provides the essentials for building web
applications without the complexity of a full-stack framework.
• Pyramids – A flexible and minimalist web framework for building small to largescale
web applications.
Data Science and Analytics
• NumPy – A library for numerical computing that provides support for large,
multidimensional arrays and matrices.
• Pandas – A library for data manipulation and analysis, offering data structures and
functions to efficiently work with structured data.
• Matplotlib – A plotting library for creating ststic, interactive, and animated
visualizations in Python.
• Scikit-learn – A machine learning library that provides simple and efficient tools for
data mining and analysis.

Machine Learning and Artificial Intelligence


• TensorFlow – An open-source machine learning framework developed by Google for
building and training machine learning modules.

10
lOMoAR cPSD| 45929297

• PyTorch – An open-source deep learning framework developed by Facebook’s AI


Research lab for building neural networks.
• Keras – A high-level neural networks API built on top of Tensor-Flow and Theano,
providing a user-friendly interface for building deep learning models.
Scientific Computing
• SciPy – A library for scientific computing that builds on top of NumPy and provides a
collection of algorithms and functions for optimization, integration, interpolation, and
more.
• SymPy – A library for symbolic mathematics that allows for symbolic computation,
including algebraic manipulation, calculus, and solving equations.
Desktop GUI Applications
• Tkinter – The standard GUI toolkit for Python, included with most Python
installations, providing a simple and easy-to-use interface for building desktop
applications.
• PyQt – A set of Python bindings for the Qt application framework, enabling the
development of cross-platform desktop applications with rich graphical interfaces.
Game Development
• Pygame – A set of Python modules designed for writing video games, providing
functionality for handling graphics, sound, and user input.
Scripting and Automation
• Python is commonly used for writing scripts and automating tasks, such as system
administration, file manipulation, web scraping, and data processing.
IOT (Internet of Things) and Embedded Systems
• Python is increasingly being used for IOT development due to its simplicity and
versatility, enabling developers to build applications for IO devices and embedded
systems.

1.5 INSTALLATION OF PYTHON


Download: Get the Python installer from the official website.

Run Installer: Execute the installer file.

Customize (Optional): Adjust installation options if needed.

Add to PATH: Check the option to add Python to system PATH.

11
lOMoAR cPSD| 45929297

Complete Installation: Follow the prompts to finish installation.

Verify: Check Python installation using ‘python – version’ in CMD.

Start Using: Access Python via command line with ‘python,’ or create and run Python
scripts.

Fig 1 showing the official website of python.

Download Python Installer --- https://www.python.org/.

Fig 1. Official website Python

1.6 REQUIREMENTS OF PYTHON

The hardware and software requirement for Python development and execution are
relatively minimal, making it accessible across a wide range of devices and platforms.

HARDWARE REQUIREMENT

CENTRAL PROCEESING UNIT (CPU)


• Python itself is not particularly resource-intensive and it can run on a wide range of
CPUs, from low-power devices to high-performance servers.
MEMORY (RAM)

12
lOMoAR cPSD| 45929297

• The amount of RAM required depends on the complexity of Python applications and
the size of datasheets that working with. For basics development and execution, even
system with few gigabytes of RAM should suffice.
STORAGE SPACE
• Python’s core installation does not require much disk space. However, the disk space
needed may vary depending on the size of the project and the dependencies/libraries
that install. A few gigabytes of storage space should be more than enough for most
Python projects.

(a) (b)

(c)

Fig 2. Hardware Requirements of Python (a) i3 processor (b) RAM (c) Storage.

SOFTWARE REQUIREMENT

Operating System
• Python is compatible with various operating systems, including Windows, Macintosh,
Linux distributions (e.g., Ubuntu, Debian, CentOS).
• Python code written on one operating system can typically run on other without
modification, thanks to Python’s cross-platform compatibility.
Python Interpreter
You need a Python interpreter to run Python code. You can download and install the
official Python interpreter from the Python Software Foundation's website: Python
Downloads.
Integrated Development Environment (IDE)
While not strictly required, using an IDE or text editor can greatly enhance your

13
lOMoAR cPSD| 45929297

Python development experience. Some popular choices include: PyCharm, Visual


Studio Code (with Python extension), Sublime Text, Atom, Vim, Emacs are shown in
Fig 3.
Package Manager
Python's package manager, pip, comes bundled with Python installations starting from
Python 3.4.
Optional: Virtual Environments
While not mandatory, using virtual environments (‘virtualenv’ or ‘venv’) is considered
a best practice for managing dependencies. You can create virtual environments to
isolate your Python projects and their dependencies, ensuring consistency and
avoiding conflicts between different projects.
Optional: Dependency Management Tools
• Depending on your project's requirements, you may need additional tools for managing
dependencies, such as:
• requirements.txt files for specifying project dependencies.

Python's minimal hardware and software requirements contribute to its popularity and
accessibility, allowing developers to write and run Python code on a wide range of devices and
platforms with ease.

IDE (Integrated Development Environment)

Fig 3. Various IDEs for Python development.

1.7 UNDERSTANDING THE EXECUTION OF PYTHON


The execution of the Python program involves two steps:

14
lOMoAR cPSD| 45929297

1) Compilation
2) Interpreter

Fig 4. Execution of Python Program.

15
lOMoAR cPSD| 45929297

2. KEY CONCEPTS

2.1 LITERAL CONSTANTS


• It is called a literal because it is literal – use its value literally.
• The number 2 always represents itself and nothing else – it is a constant because its
value cannot be changed.
• 7,3,9,’A’ and ‘Hello’ all are literals constants.
• Hence, all these are referred to as literal constants.

There are two types of literal constants

1) Numbers 2)
Strings

NUMBERS

• There can be use of four type of numbers in python program.


• Integers - 5,1000, 520,250, etc.,
• Long integers – 535633629843L
• Floating points – 3.23, 91.5E-2 (E notation indicates power of 10 91.5*10^-2)
• Complex numbers – a+bi form -3+7i
• Commas are never used in numeric literals 10,20,30,40 are not allowed in python.
• There is no limit to size of an integer.
• Floating point numbers do not have limited range and limited precision.
• Range – 10^-308 to 10^308 Precision – 10to 17 digits.

ISSUES WITH FLOATING POINT

• Arithmetic overflow problem – 2.7e00+4.3e200 result would be inf.


• Arithmetic underflow problem – 3.0e-400/5.0e200 result 0.0
• Loss of precision – 1/3=0.33333333333 where 3 is repeated infinitely.

STRINGS

• Using Single Quotes – ‘Hello’


• Using Double Quotes – “Hello”

16
lOMoAR cPSD| 45929297

• Using Triple Quotes – Multiline strings


• ‘’’Good morning, everyone, “Welcome to the world of ‘Python’,” Happy Reading””

ESCAPE SEQUENCES

•Some characters like (“, \) cannot be directly specified


in a string.
•Example – print (‘What your name?’) Syntax error –

Invalid Syntax print (‘What\’s your name?’): correct

\n = New line, \t = Tab space, \b = Back space.

2.2 VARIABLES & IDENTIFIERS

• Variables are reserved memory, locations that stores values.


• To be identified easily every variable is given a name.
• Variables are examples of identifiers.
• Identifiers are names given to variables, functions, class ---- etc.,

RULES FOR NAMING IDENTIFIERS

• Starts with Alphabets or Underscore.


• These are case sensitive.
• No special characters are allowed except underscore.
• Digits (0-9), letters, _ are only allowed.

2.3 DATA TYPES


Variables can hold values of different types are called datatypes.
Based on datatype of a variable interpreter reserves memory.

17
lOMoAR cPSD| 45929297

Fig 5. Python Datatypes

I. NUMBER SYSTEM (Numeric Datatypes)

PREFIX INTERPRETATION BASE


0b (Zero + lowercase letter Binary 2
‘b’)
0B (Zero + uppercase letter
‘B’)
0o (Zero + lowercase letter Octal 8
‘o’)
0O (Zero + uppercase letter
‘O’)
0x (Zero + lowercase letter Hexadecimal 16
‘x’)
0X (Zero + uppercase letter
‘X’)
II. COMPLEX DATATYPES
Representation is a+bj
Example – a=2+3j

Type () – This function is used to determine the type of an object as in Figure 6. It returns the
type of the object as a class object.

18
lOMoAR cPSD| 45929297

Fig 6. Type () function in Python

III. BOOLEAN
The Boolean data type is either True or False.
In Python, Boolean variables are defined by the True and False keywords.

IV. COLLECTIONS

Collections refers to data structures that are used to store and manage collections of data. These
collections provide various functions and are designed to suit different needs. Collections in
python are basically container data types, namely lists, sets, tuples, dictionary.
Here an introduction to collections in Python along with some commonly used types:
LISTS

List are ordered collections of items.


They are mutable, meaning their content can be changed after creation.
List are created using square brackets ‘[]’.
Example: ‘my_list = [1, 2, 3, 4, 5, 6]’

TUPLES

19
lOMoAR cPSD| 45929297

Tuples are similar to lists but are immutable, meaning their content cannot be changed after
creation.
Tuples are created using parentheses ‘()’.
Example: ‘my_tuples = (1, 2, 3, 4, 5, 6)’

SETS

Sets are unordered collections of unique elements.


They are mutable, but their elements must be immutable.
Sets are created using curly braces ‘{}’ or the ‘set()’ function.
Example: ‘my_set = {1, 2, 3, 4, 5, 6}’

DICTIONARIES

Dictionaries are collection of key-value pairs.


They are unordered, mutable, and can contain any data types as values.
Dictionaries are created using curly braces ‘{}’ with key-value pairs separated by colons :
Examples: ‘my_dict = {‘name’: ‘John’, ‘age’: ‘24’, ‘city’: ‘New York’}’

2.4 OPERATIONS
In Python, operators are special symbols or keywords that are used to perform
operations on operands. Here is an overview of the different types of operators in Python:

ARITHMETIC OPERATORS

Arithmetic operators are used to perform mathematical operations as in Figure 7.

Addition: ‘+’
Subtraction: ‘-’
Multiplication: ‘*’
Division: ‘/’
Floor Division: ‘//’ (returns the integer part of the division)
Modulus: ‘%’ (returns the remainder of the division)
Exponentiation: ‘**’ (raises the left operand to the power of the right operand)

20
lOMoAR cPSD| 45929297

Fig 7. Arithmetic Operators in Python.

COMPARISON OPERATIONS
Comparison operators are used to compare the values of two operands as shown in Figure 8.
Equal to: ‘==’
Not equal to: ‘! =’
Greater than: ‘>’
Less than: ‘<’
Greater than or equal to: ‘>=’
Less than or equal to: ‘<=’

Fig 8. Comparison Operators in Python.

LOGICAL OPERATORS
Logical operators are used to combine conditional statements as in Figure 10.
Logical AND – ‘and’
Logical OR – ‘or’
Logical NOT – ‘not’

21
lOMoAR cPSD| 45929297

Fig 9. Logical Operators in Python.

ASSIGNMENT OPERATORS
Assignment operators are used to assign values to variables as in Figure 11.
Assignment: ‘=’
Addition assignment: ‘+=’
Subtraction assignment: ‘ -=’
Multiplication assignment: ‘*=’
Division assignment: ‘/=’
Modulus assignment: ‘%=’
Floor division assignment: ‘//=’
Exponentiation assignment: ‘**=’

Fig 10. Assignment Operators in Python.


BITWISE OPERATION
Bitwise operators are used to perform bitwise operations on integers as in Figure 12.
Bitwise AND: ‘&’
Bitwise OR: ‘|’
Bitwise XOR: ‘^’
Bitwise NOT: ‘ ~’ Left shift: ‘<<’
Right shift: ‘>>’

22
lOMoAR cPSD| 45929297

Fig 11. Bitwise Operators in Python.

2.5 TYPE CASTING VS TYPE COERCION

Type casting and type coercion are both mechanisms used in programming language to
convert data from one type to another, but they differ in their approaches and implications.

• Explicit conversion of a value from one datatype to another is called type casting.
• Implicit conversion of datatypes during compilation or runtime is called Type Coercion.

TYPE CONVERSION
Type conversion, also known as type casting, is the process of converting a value from one
data type to another. In Python, it can perform type conversion using built-in functions or
constructors. Here are some common type conversion functions:

Int(x) : Converts x to integer Float(x) : Converts x to float Str(x) : Converts x to


string.
Tuple(x) : Converts x to tuple.
List(x) : Converts x to list.
Set(x) : Converts x to set
Ord(x) : Converts ASCII value of characters x Oct(x) : Converts x to octal.
Hex(x) : Converts x to hexadecimal.
Chr(x) : Converts ASCII code to characters.

23
lOMoAR cPSD| 45929297

3. CONTROL STATEMENTS
In Python, control statements are used to control the flow of execution in a program based on
certain conditions. They allow to make decisions, execute code repeatedly, and handle
exceptions. Three fundamental methods of control flow:

1) Sequential
2) Selection (execution only a selected set of stmts)
3) Iteration (execute a set of statements repeatedly)

SELECTION / CONDITIONAL BRANCHING

• These statements usually jump from one part of code to another depending on whether a
particular condition is satisfied or not.
• Conditional statements execute sequentially when there is no condition around the
statements.
• If you put some condition for a block of statements, the execution flow may change based
on the result evaluated by the condition.

If: An if statement is a programming condition that, if proved true, perform a function, or


displays information. The flow chart for if statement is shown in Figure 13.

Fig 13. Flowchart for if statement in Python.

24
lOMoAR cPSD| 45929297

SAMPLE PROGRAM

Program to increment a number if positive

If you input a positive number like 5, the program will increment it by 1, resulting in 6 as the
output. If you input a number that is not positive, such as 0 or a negative number, the program
will not increment it, and the output will be the same as the input number.

Nested if: Nested if statements mean an if statement inside another is statement. The flow chart
for if statement is shown in Figure 14.

Fig 14. Flowchart for nested if statement in Python.

SAMPLE PROGRAM

Program to print the given year is leap year or not

25
lOMoAR cPSD| 45929297

If the input the year 2024, the program will determine that it is a leap year and print "2024 is a
leap year".

If-else: The if-else statement evaluates test expression and will execute the body of if only
when the test condition is True. If the condition is False, the body of else is executed.
Indentation is used to separate the blocks.

If-elif-else: The if-elif-else statements is used to conditionally execute a statement or a block


of statements. Conditions can be true or false, execute one thing when the condition is true,
something else when the condition is false.

ITERATIVE STATEMENTS

WHILE LOOP
In the while loop, test expression is checked first. The body of the loop is entered only if
the test expression evaluates to True. After one iteration, the test expression is checked
again. This process continues until the test expression evaluates to False. The flow chart of
while loop is in the figure 15.

26
lOMoAR cPSD| 45929297

Fig 15. Flowchart for while loop in Python.

PYTHON BREAK STATEMENTS

The break statements terminate the loop containing it. Control of the program flow to the
statements immediately after the body of the loop. If the break statements is inside a nested
loop (loop inside another loop), the break statement will terminate the innermost loop.

Example – Usage break in a while loop

27
lOMoAR cPSD| 45929297

In this example, the while loop continues as long as num is less than 5. Inside the loop, num is
printed, and then it is checked whether num is equal to 3. If the condition is true, the break
statement is executed, and the loop terminates

PYTHON CONTINUE STATEMENT

The continue statement is used to skip the rest of the code inside a loop for the current iteration
only. Loop does not terminate but continues on with the next iteration.

Example – Using continue in a while loop

In this example, the while loop continues as long as Num is less than 5. Inside the loop,
Num is incremented by 1. Then, it is checked whether Num is equal to 2. If the condition is
true, the continue statement is executed, and the loop skips the remaining code block for
that iteration. Otherwise, the value of Num is printed.

FOR LOOP
For loop is usually known as determinate or definite loop because the programmer knows
exactly how many times the loop will repeat. The number of times loop has to be executed
can be determined mathematically checking logic of the loop. The flow chart of for loop is
shown in figure 16.
Syntax
For loop_control_var in sequence:
Statement 1
Statement 2

28
lOMoAR cPSD| 45929297

Fig 16. Flowchart for loop in Python.

SAMPLE PROGRAM

Program using for loop to check whether the number is even or odd

Each number from 1 to 10 is printed along with whether it is odd or even. Odd numbers have
a remainder of 1 when divided by 2, while even numbers have a remainder of 0.

29
lOMoAR cPSD| 45929297

NESTED LOOPS

Nested loops in Python refer to using one or more loops inside another loop. This allows you
to iterate over a sequence of elements or perform a certain operation multiple times, with one
loop contained within another loop.

The basic syntax for a nested loop in Python is as follows:

for outer_loop_variable in outer_sequence: #

Code block for Outer loop for

inner_loop_variable in inner_sequence:

# Code block for inner loop

Nested loops are commonly used when dealing with multi-dimensional data structures, such as
lists of lists or matrices, or when you need to perform a repetitive task that involves multiple
levels of iteration.

Example – Simple example of a nested loop to print a pattern

In this example, the outer loop (for i in range (5)) iterates over the rows, and the inner loop
which (for j in range (i + 1)) iterates over the columns for each row. This results in a pattern
where the number of asterisks increases with each row.

30
lOMoAR cPSD| 45929297

4. FUNCTIONS
INTRODUCTION

A function is a block of organised and reusable program code that performs a simple,
specific, and well-defined task.
Func (1) is called to perform a well-defined task. As soon as Func (1) is called, the program
control is passed to first statement in function. All the statements in function are executed
and program control is passed to function following the one that called the function.

FUNCTION CALLING ANOTHER FUNCTION

Func (1) calls function named Func (2). Therefore Func (1) is known as calling function.
Func (2) is known as function.

NOTE: Func (1) calls as many functions as it wants.

4.1 NEED FOR FUNCTIONS


Dividing the program into separate functions facilitates each function to be written and
tested separately.
Understanding, coding and testing multiple separate functions are far easier than the doing
same for one huge function.
If a big program is done without functions, then there will be a large line of codes and
maintaining it is a big mess.
All libraries in python contains predefined and pre-tested functions which the programmer
can use them directly.
When a big program is broken into smaller functions different programmers working on
that project can divide the workload.
Code reuse is one of the most prominent reasons to use the functions.

4.2 BUILT-IN MATH FUNCTIONS

Python provides a built-in math module that contains a variety of mathematical


functions for performing common mathematical operations. Here are some of the most used
math functions available in Python:

31
lOMoAR cPSD| 45929297

• abs(x): Returns the absolute value of x.


• pow (x, y) or x ** y: Returns x raised to the power of y.
• sqrt(x): Returns the square root of x.
• exp(x): Returns the exponential value of x (e^x).
• log(x): Returns the natural logarithm of x (base e).
• log10(x): Returns the base-10 logarithm of x.
• sin(x), cos(x), tan(x): Returns the trigonometric sine, cosine, and tangent of x,
respectively. The input x is in radians.
• asin(x), acos(x), atan(x): Returns the inverse trigonometric sine, cosine, and tangent of
x, respectively. The result is in radians.
• degrees(x): Converts angle x from radians to degrees.
• radians(x): Converts angle x from degrees to radians.
• ceil(x): Returns the smallest integer greater than or equal to x (i.e., the ceiling of x).
• floor(x): Returns the largest integer less than or equal to x (i.e., the floor of x).
• round(x): Returns x rounded to the nearest integer.
• gcd(x, y): Returns the greatest common divisor of two integers x and y.
• hypot(x, y): Returns the Euclidean norm, sqrt(xx + yy).

4.3 FUNCTION ASPECTS


The inputs that function takes are called as arguments or parameters.
When a called function returns some results to calling function it is said to return result.
The calling function may or may not pass parameters.
Function Declaration is a declaration statement that identifies a function with its name,
list of arguments, and type of data it returns.
Function Definition consists of a function header that identifiers the function, followed
by body of function containing executable code for that function.

FUNCTION DEFINITION

• Function blocks begin with the keyword def followed by the function name and
parentheses().
• Any input parameters or arguments should be placed within these parentheses().
• The first statement of a function can be an optional statement – the documentation string
of the function or docstring.

32
lOMoAR cPSD| 45929297

• The statement return [expression] exists a function, optionally passing back an


expression the caller. A return statement with no arguments is the same as return None.

FUNCTION CALL

• The function call statement invokes the function.


• When a function is invoked the program control jumps to called functions to execute
statements that are part of a function.
• Once called function is executed the program control passes back to calling function.
• Function_name ().

33
lOMoAR cPSD| 45929297

5. FILES AND DATA STRUCTURES

INTRODUCTION
File is a collection of data stored on a secondary storage device like hard disk.
If working in a large software application where they process many data, then it cannot
expect those data to be stored in a variable as the variables are volatile in nature.
Hence when it handles such situations, the role of files will come into the picture.
As files are non-volatile in nature, the data will be stored permanently in a second device
like Hard Disk and using python it can handle the files in applications.

TYPES OF FILES

There are two types of files in Python. They are:

1) Binary file
2) Text file

BINARY FILE

Most of the files that visible in personal computer system are called binary files.

• Document Files - .pdf, .doc, .xls etc


• Image Files - .png, .jpg, .gif, .bmp etc
• Video Files - .mp4, .3gp, .mkv, .avi etc
• Audio Files - .mp3, .wav, .mka, .aac etc
• Database Files - .mdb, .accde, .frm, .sqlite etc
• Archive Files - .zip, .rar, .iso, .7z etc
• Executable Files - .exe, .dll, .class etc

All binary files follow a specific format. It can open some binary files in the normal text
editor but it cannot read the content present inside the file. That is because all the binary files
will be encoded in the binary format, which can be understood only by a computer or
machine.

For handling such binary files it can need a specific type of software to open it.
For Example – it needs Microsoft word software to open .doc binary files. Likewise, it need
a .pdf reader software to open .pdf binary files and it need a photo editor software to read the
image files and so on.

34
lOMoAR cPSD| 45929297

TEXT FILE

Text files do not have any specific encoding and it can be opened in normal text editor itself.

• Web Standards – html, XML, CSS, Java etc


• Source Code – C, apps, Js, Py, Java etc
• Documents – txt, tex, RTF etc
• Tabular Data – scv, tsv etc
• Configuration – ini, cfg, reg etc

5.1 PYTHON FILE HANDLING OPERATION

Most importantly there are four types of operations that handled by Python on files:

OPENING A FILE

Python has an in-built function called open () to open a file.


The open method returns a file object which is used to access the write, read and other
inbuilt methods.

SYNTAX

File_object = open(file_name,mode)
File_name is the name of the file or the location of the file that want to open.

MODE

• The file in the open function syntax will tell Python as what operation that what to do on a
file.
• ‘r’ – Read Mode : Read mode is used only to read data from the file.
• ‘w’ – Write Mode : This mode is used when it want to write data into a file or modify it.
Remember write mode overwrites the data present in the file.
• ‘s’ – Append Mode : Append mode is used to append data to the file. Remember data will
be appended at the end of the file pointer.

• ‘r+’ – Read or Write Mode : This mode is used when it want to write or read the data
from the same file.
• ‘w+’ – Read or Write Mode : When a file is opened in this mode. If the file has not been
created new file will be created if created it is overwritten.

35
lOMoAR cPSD| 45929297

• ‘a+’ – Append or Read Mode : This mode is used when it want to read data from the file
or append the data into the same file.

BINARY MODE

• ‘wb’ – Open a file for write only mode in the binary format.
• ‘rb’ – Open a file for the read -only mode in the binary format.
• ‘ab’ – Open a file for appending only mode in the binary format.
• ‘rb+’- Open a file for read and write only mode in the binary format.
• ‘ab’ - Open a file for appending and read only mode in the binary format.

READ A FILE

There are three ways in which we can read the files in python
Read([n])
Readline([n])
Readlines()

Here, n is the number of bytes to be read.

Program to read specific line from a file

lineno=int(input(“enter a number”))

fp=open(“hello.txt”,”r”) cufrentline=1 for

line in fp: if(currentline==lineno):

print(line)

break

PYTHON CLOSE A FILE:

In order to close a file, we must first open a file. In python, we have an in built method
called close() to close the file which is opened.
Whenever you open a file, it is important to close it, especially, with write method. Because
if we don’t call the close function after the write method then whatever data we have written
to a file will not be saved in to the file.

Example

36
lOMoAR cPSD| 45929297

My_file= open(“C:/Documents/Pythhon/test.txt”, “r”)

Print(my_file.read())

My_file.close()

WRITE A FILE:

In order to write data into a file, we must open the file in the write mode.
We need to be very careful while writing data in to the file as it overwrites the content
present inside the file that you were writing, and all previous data will be erased.
We have two methods for writing data into a file as shown below.
Write(string)
Writelines(list) Write() my_file=open(“C:/Documents/Python/test.txt”, “w”)

my_file.write(“Hello World/n”) my_file. Write(“Hello Python”)

Writelines()

• Fruits=[“Apple/n”, “Orange/n”, “Grapes/n”, “Watermelon”]


• My_file=open(“C:/Documents/Python/test.txt”, “w”)
• My_file. Writelines(fruits)
• My_ file. Close()

PYTHON APPEND TO FILE:

My_file=open(“C:/Documents/Python/test.txt”, “a+”)

My_file.write(“Strawberry”)

The above code appends the string ‘strawberry’ at the end of the ‘test.txt’file.

APPENDING A LIST OF DATA:

Fruits=[“ /n Banana”, “/n Avacado”, “/nFigs”, “/n Mango”]

My_file=open(“C:/Documents/Python/test.txt”, “w”)

My_file. Writelines(fruits)

The above code appends a list of data into a “test.txt” file.

37
lOMoAR cPSD| 45929297

6. STRUCTURED QUERY LANGUAGE


6.1 INTRODUCTION

SQL, or Structured Query Language, is a powerful programming language used for


managing and manipulating relational databases. It provides a standardized way to interact with
databases, allowing users to perform tasks such as querying data, updating records, and
defining database structures. Originally developed in the 1970s by IBM, SQL has since become
the de facto standard language for relational database management systems (RDBMS),
including popular systems such as MySQL, PostgreSQL, Microsoft SQL Server, Oracle
Database, and SQLite, among others.

KEY ASPECTS

Data Querying: SQL allows users to retrieve data from databases using queries. Queries
can range from simple requests for specific records to complex operations involving
multiple tables and conditions.
Data Manipulation: SQL provides commands for inserting, updating, and deleting data
within a database. This allows users to modify existing records or add new ones as needed.
Database Definition: SQL includes commands for defining and managing database
structures such as tables, indexes, views, and stored procedures. These structures help
organize and optimize data storage and access.
Data Control: SQL offers mechanisms for controlling access to databases and managing
user permissions. This ensures that only authorized users can view or modify sensitive data.
Data Integrity: SQL supports the enforcement of data integrity constraints such as primary
keys, foreign keys, and unique constraints. These constraints help maintain the consistency
and reliability of data within a database.
Transaction Control: SQL provides features for managing database transactions, allowing
users to group multiple database operations into atomic units of work. This ensures that
either all operations within a transaction are completed successfully or none of them are,
maintaining data consistency.

6.2 IMPORTANCE OF SQL

Decision Making: Data-driven decision making relies on analysing data to make informed
choices, whether in business strategy, healthcare, or other fields.

38
lOMoAR cPSD| 45929297

Business Insights: Data can provide valuable insights into customer behaviour, market
trends, and operational efficiency, helping businesses optimize their strategies.
Predictive Analysis: By analysing historical data, organizations can make predictions
about future trends and outcomes, aiding in planning and risk management.
Personalization: Data allows businesses to personalize products, services, and marketing
efforts to better meet the needs and preferences of individual customers.
Performance Monitoring: Monitoring key performance indicators (KPIs) through data
analysis helps organizations track progress towards goals and identify areas for
improvement.

6.3 TYPES OF DATA

Structured Data: This type of data has a predefined data model or is organized in a tabular
format with a clear schema, making it easy to query and analyze. Examples include data in
relational databases or spreadsheets.
Unstructured Data: Unstructured data lacks a predefined data model and is not organized
in a structured manner. Examples include text documents, images, audio files, and videos.
Analysing unstructured data often requires specialized tools and techniques such as natural
language processing (NLP) or computer vision.
Semi-Structured Data: Semi-structured data falls somewhere between structured and
unstructured data. It may have a flexible schema or tags that provide some structure, but it
does not fit neatly into a relational database. Examples include JSON, XML, and log files.
Transactional Data: Transactional data records specific events or transactions, typically
in a structured format. Examples include sales transactions, financial transactions, and log
entries.
Temporal Data: Temporal data includes information related to time, such as timestamps
or time-series data. It is commonly used in applications where the temporal aspect is
important, such as IoT (Internet of Things) devices, financial markets, and weather
forecasting.

6.4 DATA TYPES


In SQL, data types define the type of data that can be stored in a column of a table or
used as variables within SQL statements. Different database management systems (DBMS)
may support slightly different sets of data types, but there are common types found across most
SQL implementations.

39
lOMoAR cPSD| 45929297

Here is an overview of common data types and their categories:

1) NUMERIC DATA TYPE

• INTEGER/INT: Stores whole numbers, typically within a specified range.


• SMALLINT: Like INTEGER but with a smaller range.
• BIGINT: Like INTEGER but with a larger range.
• DECIMAL/NUMERIC: Stores fixed-point numbers with exact precision.
• FLOAT/REAL: Stores approximate numeric values with floating-point precision.
DOUBLE PRECISION: Like FLOAT but with double precision.

2) CHARACTER STRING DATA TYPES:

• CHAR(n): Fixed-length character strings with a specified length 'n'.


• VARCHAR(n): Variable-length character strings with a maximum length 'n'.
• TEXT: Variable-length character strings with no specified maximum length (often used for
large text data).

3) BINARY DATA TYPES:

• BINARY(n): Fixed-length binary strings with a specified length 'n'.


• VARBINARY(n): Variable-length binary strings with a maximum length 'n'.
• BLOB: Variable-length binary strings with no specified maximum length (often used for
large binary data).

4) DATE AND TIME DATA TYPES:

• DATE: Stores date values in the format YYYY-MM-DD.


• TIME: Stores time values in the format HH:MM: SS.
• DATETIME/TIMESTAMP: Stores both date and time values. INTERVAL: Represents a
time interval.

5) BOOLEAN DATA TYPE:


BOOLEAN/BOOL: Stores true or false values.

6) ENUMERATION DATA TYPES:

ENUM: Represents a set of predefined values.

7) OTHER DATA TYPES:

• ARRAY: Stores an array of values.

40
lOMoAR cPSD| 45929297

• JSON: Stores JSON (JavaScript Object Notation) data.


• XML: Stores XML (extensible Markup Language) data.
• GEOMETRY/GEOGRAPHY: Stores spatial data for geographic information systems
(GIS).

6.5 INSTALLATION OF SQL

1) Download MySQL Installer: Visit the MySQL website and download the MySQL
Installer for your operating system (Windows, macOS, Linux).
2) Run Installer: Locate the downloaded installer file and double-click it to run the installer.
3) Choose Installation Type: Select your preferred installation type (e.g., "Developer
Default" for standard development setup) and click "Next".
4) Configure MySQL Server: Set the root password for MySQL Server and choose a port
number for MySQL to listen on.
5) Complete Installation: Wait for the installer to finish installing components and
configuring MySQL Server.

Fig 17. Run SQL through Oracle

6.6 CREATION OF TABLES, DATABASE, INSERTING VALUES

Creating Table – Syntax

CREATE TABLE table_name(column_name data_type);

EXAMPLE

CREATE TABLE Student(Student id int, Student_name varchar2(30), Student_DOB date,


Student_age int):

41
lOMoAR cPSD| 45929297

Inserting values into the table – syntax

INSERT INTO table name VALUES (value1,value2.....);

EXAMPLE

INSERT INTO Student values (1,’Rahul’, ’31-AUG-1998’, 24);

6.7 SELECT, WHERE, PROJECTION AND SELECTION

1) SELECT – The SELECT statement in SQL is used to retrieve data from table in a database.

Syntax - SELECT column1, column2,...FROM table... name;

Example - SELECT first_name, last_name, salary FROM employees:

2) WHERE - The WHERE clause is used to filter rows based on a specified condition. It

allows you to retrieve only the rows that meet the specified criteria Syntax - SELECT

column1,column2,... name where conditions

Example - select” from employees where employee_ name=’sahana’;

3) PROJECTION - a query retrieves specific columns from a table

Example - select employee_ name from employees

4) SELECTION - a selection query filters rows from a table based on specific conditions

Example - select’ employees where employee _ name = ‘sahana’;


6.8 CASE SENSITIVITY

• SQL command (e.g., SELECT, INSERT) are not case – sensitive.


• SQL keywords (e.g., SELECT, FROM, WHERE) are not case – sensitive.
• Data is not case-sensitive. For example, ‘Hello’ and ‘hello’ are considered as equivalent
values.
• Column names are not case-sensitive.
• Table names are not case-sensitive.

42
lOMoAR cPSD| 45929297

6.9 OPERATORS

SQL operators are used to perform operations on data in SQL queries. These are the
basic syntax patterns for using common SQL operators in queries. Keep in mind that the exact
syntax may vary slightly depending on the SQL dialect or database management system you're
using.

Here is a summary of some common SQL operators:

ARITHMETIC OPERATORS:

• + (Addition): Adds two values.


• - (Subtraction): Subtracts one value from another.
• (Multiplication): Multiplies two values.
• / (Division): Divides one value by another.
• % (Modulo): Returns the remainder of a division operation.

COMPARISON OPERATORS:

• = (Equal to): Tests if two values are equal.


• or != (Not equal to): Tests if two values are not equal.
• < (Less than): Tests if one value is less than another.
• (Greater than): Tests if one value is greater than another.
• <= (Less than or equal to): Tests if one value is less than or equal to another.
• >= (Greater than or equal to): Tests if one value is greater than or equal to another.
LOGICAL OPERATORS:

• AND: Returns true if all conditions separated by AND are true.


• OR: Returns true if any condition separated by OR is true.
• NOT: Negates the result of a condition.

CONCATENATION OPERATOR:

• || (Double Pipe): Concatenates two or more strings.

PATTERN MATCHING OPERATORS (USED WITH LIKE):

• %: Matches any sequence of characters (zero or more).


• _ (Underscore): Matches any single character.

43
lOMoAR cPSD| 45929297

• [ ]: Matches any single character within the specified range or set.


• [^ ]: Matches any single character not within the specified range or set.

IN OPERATOR:

• Checks if a value matches any value in a list of specified values.

BETWEEN OPERATOR:

• Checks if a value is within a range of values.

IS NULL OPERATOR:

• Checks if a value is NULL.

IS NOT NULL OPERATOR:

• Checks if a value is not NULL.

44
lOMoAR cPSD| 45929297

7. CONCLUSION
Python full stack development offers a comprehensive approach to building web applications
using Python for both frontend and backend development. Here is a concise conclusion
highlighting its key aspects:

Python's versatility and simplicity make it an excellent choice for full stack development.
With Python, developers can use the same language across the entire stack, from frontend
to backend, reducing complexity and streamlining development.
For frontend development, Python frameworks like Django and Flask offer powerful tools
for building robust web applications. These frameworks provide features such as routing,
templating, form handling, and authentication, allowing developers to create dynamic and
interactive user interfaces.
On the backend, Python's extensive ecosystem of libraries and frameworks, combined with
its ease of integration with databases and other services, enables developers to build
scalable and efficient server-side applications.

Overall, Python full stack development offers a cohesive and efficient approach to building
modern web applications, leveraging Python's strengths in simplicity, versatility, and extensive
ecosystem of libraries and frameworks. As a result, Python remains a popular and widely-used
technology stack for developers seeking to build robust and scalable web applications.

45

You might also like