GOVERNMENT POLYTECHNIC
KASHIPUR
Industrial Training Report
On
Python Programming
Submitted To: Submitted By:
Pooja
Branch: I.T.
Roll No.:21009120021
1
Declaration
I hereby declare that the Industrial training report entitled “PYTHON
PROGRAMMING” done at “GICT HALDWANI” submitted by
me. It is international IT Certification Institute, vision to train IT
workforce with global values for India abroad. Excellence of 5yrs in
advanced IT training [corporate and Retail], International IT
Certifications, IT Infra development and support, recruitments
solutions has made GICT with a bonafide work carried out at
Haldwani between 01-07-2023 to 31-07-2023.
Place: Kaladhungi Road,
Haldwani
Signature of candidate:
2
Contents
S. No. Title
1. Introduction
2. Python getting started
3. Python comments
4. Python variables
5. Python data types
6. Python numbers
7. Python strings
8. Python lists
9. Python tuples
10. Python sets
11. Python dictionaries
12. Python string methods
13. Python operators
14. Python Booleans
15. Python if…..else
16. Python loops
17. Python functions
18. Python try…except
19. Conclusion
20. References
21. Major project
3
Introduction
What is Python?
Python is an interpreted, object-oriented, high-level programming
language with dynamic semantics developed by Guido van Rossum.
It was originally released in 1991. Dessigned to be easy as well as fun,
the name "Python" is a nod to the British comedy group Monty Python.
Python has a reputation as a beginner-friendly language, replacing Java
as the most widely used introductory language because it handles much
of the complexity for the user.
Python is an open source community language, so numerous
independent programmers are continually building libraries and
functionality for it.
What can Python do?
Python can be used on a server to create web
applications.
Python can be used alongside software to create
workflows.
Python can connect to database systems. It can also read
and modify files.
Python can be used to handle big data and perform
complex mathematics.
Python can be used for rapid prototyping, or for
production-ready software development.
4
Good to know
The most recent major version of Python is Python 3,
which we shall be using in this tutorial. However, Python
2, although not being updated with anything other than
security updates, is still quite popular.
In this tutorial Python will be written in a text editor. It is
possible to write Python in an Integrated Development
Environment, such as Thonny, Pycharm, Netbeans or
Eclipse which are particularly useful when managing larger
collections of Python files.
Python Syntax compared to other programming languages
Python was designed for readability, and has some
similarities to the English language with influence from
mathematics.
Python uses new lines to complete a command, as
opposed to other programming languages which often use
semicolons or parentheses.
Python relies on indentation, using whitespace, to define
scope; such as the scope of loops, functions and classes.
Other programming languages often use curly-brackets
for this purpose.
5
Python Getting Started
Python Install
Many PCs and Macs will have python already installed.
To check if you have python installed on a Windows PC, search
in the start bar for Python or run the following on the
Command Line (cmd.exe):
C:\Users\Your Name>python --version
To check if you have python installed on a Linux or Mac, then
on linux open the command line or on Mac open the Terminal
and type:
python --version
If you find that you do not have Python installed on your
computer, then you can download it for free from the following
website: https://www.python.org/
Python Quickstart
Python is an interpreted programming language, this means
that as a developer you write Python (.py) files in a text editor
and then put those files into the python interpreter to be
executed.
The way to run a python file is like this on the command line:
C:\Users\Your Name>python helloworld.py
Where "helloworld.py" is the name of your python file.
Let's write our first Python file, called helloworld.py, which can
be done in any text editor.
6
helloworld.py
print("Hello, World!")
Simple as that. Save your file. Open your command line,
navigate to the directory where you saved your file, and run:
C:\Users\Your Name>python helloworld.py
The output should read:
Hello, World!
7
Python Comments
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Creating a Comment
Single Line Comments
Comments starts with a #, and Python will ignore them:
Example
#This is a comment
print("Hello, World!")
Comments can be placed at the end of a line, and Python will ignore the rest of
the line:
Example
print("Hello, World!") #This is a comment
A comment does not have to be text that explains the code, it can also be used to
prevent Python from executing code:
Example
#print("Hello, World!")
print("Cheers, Mate!)
Multiline Comments
Python does not really have a syntax for multiline comments.
To add a multiline comment you could insert a # for each line:
8
Example
#This is a comment
#written in
#more than just one line
print("Hello, World!")
Or, not quite as intended, you can use a multiline string.
Since Python will ignore string literals that are not assigned to a variable, you
can add a multiline string (triple quotes) in your code, and place your comment
inside it:
Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
As long as the string is not assigned to a variable, Python will read the code, but
then ignore it, and you have made a multiline comment.
Test You
9
rPython Variables
Variables are containers for storing data values.
Creating Variables
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
Example
x = 5
y = "John"
print(x)
print(y)
Variables do not need to be declared with any particular type,
and can even change type after they have been set.
Example
x = 4 # x is of type int
x = "Sally" # x is now of type str
print(x)
Casting
If you want to specify the data type of a variable, this can be
done with casting.
Example
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
10
Get the Type
You can get the data type of a variable with
the type() function.
Example
x = 5
y = "John"
print(type(x))
print(type(y))
Single or Double Quotes?
String variables can be declared either by using single or
double quotes:
Example
x = "John"
# is the same as
x = 'John'
Case-Sensitive
Variable names are case-sensitive.
Example
a = 4
A = "Sally"
#A will not overwrite a
11
Python - Variable Names
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for
Python variables:
A variable name must start with a letter or the underscore
character.
A variable name cannot start with a number.
A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ ).
Variable names are case-sensitive (age, Age and AGE are
three different variables).
A variable name cannot be any of the Python keywords.
Example
Legal variable names:
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Example
Illegal variable names:
2myvar = "John"
my-var = "John"
my var = "John"
Python Variables - Assign Multiple
Values
Many Values to Multiple Variables
Python allows you to assign values to multiple variables in one line:
12
Example
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
One Value to Multiple Variables
And you can assign the same value to multiple variables in one line:
Example
x = y = z = "Orange"
print(x)
print(y)
print(z)
13
Python Data Types
In programming, data type is an important concept.
Variables can store data of different types, and different types
can do different things.
Python has the following data types built-in by default, in these
categories:
Text Type: str
Numeric Types: int, float, complex
Sequence list, tuple, range
Types:
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
Getting the Data Type
You can get the data type of any object by using
the type() function:
14
Example
Print the data type of the variable x:
x = 5
print(type(x))
Setting the Specific Data Type
If you want to specify the data type, you can use the following
constructor functions:
Example Data Type
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = list(("apple", "banana", "cherry")) list
x = tuple(("apple", "banana", "cherry")) tuple
x = range(6) range
15
Python Numbers
There are three numeric types in Python:
int
float
complex
Variables of numeric types are created when you assign a value
to them:
Example
x = 1 # int
y = 2.8 # float
z = 1j # complex
To verify the type of any object in Python, use
the type() function:
Example
print(type(x))
print(type(y))
print(type(z))
Int
Int, or integer, is a whole number, positive or negative, without
decimals, of unlimited length.
Example
Integers:
x = 1
y = 35656222554887711
z = -3255522
print(type(x))
16
print(type(y))
print(type(z))
Float
Float, or "floating point number" is a number, positive or
negative, containing one or more decimals.
Example
Floats:
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
Complex
Complex numbers are written with a "j" as the imaginary part:
Example
Complex:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
Type Conversion
17
You can convert from one type to another with
the int(), float(), and complex() methods:
Example
Convert from one type to another:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
Note: You cannot convert complex numbers into another number type.
18
Python Strings
Strings in python are surrounded by either single quotation
marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
Example
print("Hello")
print('Hello')
Assign String to a Variable
Assigning a string to a variable is done with the variable name
followed by an equal sign and the string:
Example
a = "Hello"
print(a)
Multiline Strings
You can assign a multiline string to a variable by using three
quotes:
Example
You can use three double quotes:
19
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Or three single quotes:
Example
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)
Looping Through a String
Since strings are arrays, we can loop through the characters in
a string, with a for loop.
Example
Loop through the letters in the word "banana":
for x in "banana":
print(x)
String Length
To get the length of a string, use the len() function.
Example
The len() function returns the length of a string:
a = "Hello, World!"
print(len(a))
20
Python Lists
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python used to store
collections of data, the other 3 are Tuple, Set, and Dictionary,
all with different qualities and usage.
Lists are created using square brackets:
Example
Create a List:
thislist = ["apple", "banana", "cherry"]
print(thislist)
List Items
List items are ordered, changeable, and allow duplicate values.
List items are indexed, the first item has index [0], the second
item has index [1] etc.
Ordered
When we say that lists are ordered, it means that the items
have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at
the end of the list.
21
Changeable
The list is changeable, meaning that we can change, add, and
remove items in a list after it has been created.
Allow Duplicates
Since lists are indexed, lists can have items with the same
value:
Example
Lists allow duplicate values:
thislist = ["apple", "banana", "cherry", "apple", "cherry"]
print(thislist)
List Length
To determine how many items a list has, use
the len() function:
Example
Print the number of items in the list:
thislist = ["apple", "banana", "cherry"]
print(len(thislist))
List Items - Data Types
List items can be of any data type:
Example
String, int and boolean data types:
list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
22
23
Python Tuples
Tuples are used to store multiple items in a single variable.
Tuple is one of 4 built-in data types in Python used to store collections of data,
the other 3 are List, Set, and Dictionary, all with different qualities and usage.
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets.
Example
Create a Tuple:
thistuple = ("apple", "banana", "cherry")
print(thistuple)
Tuple Items
Tuple items are ordered, unchangeable, and allow duplicate values.
Tuple items are indexed, the first item has index [0], the second item has
index [1] etc.
Ordered
When we say that tuples are ordered, it means that the items have a defined
order, and that order will not change.
Unchangeable
Tuples are unchangeable, meaning that we cannot change, add or remove items
after the tuple has been created.
Allow Duplicates
Since tuples are indexed, they can have items with the same value:
24
Example
Tuples allow duplicate values:
thistuple = ("apple", "banana", "cherry", "apple", "cherry")
print(thistuple)
Tuple Length
To determine how many items a tuple has, use the len() function:
Example
Print the number of items in the tuple:
thistuple = ("apple", "banana", "cherry")
print(len(thistuple)
Tuple Items - Data Types
Tuple items can be of any data type:
Example
String, int and boolean data types:
tuple1 = ("apple", "banana", "cherry")
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
A tuple can contain different data types:
Example
A tuple with strings, integers and boolean values:
tuple1 = ("abc", 34, True, 40, "male")
25
Python Sets
Sets are used to store multiple items in a single variable.
A set is a collection which is unordered, unchangeable*,
and unindexed.
* Note: Set items are unchangeable, but you can remove
items and add new items.
Sets are written with curly brackets.
Example
Create a Set:
thisset = {"apple", "banana", "cherry"}
print(thisset)
Set Items
Set items are unordered, unchangeable, and do not allow
duplicate values.
Unordered
Unordered means that the items in a set do not have a defined
order.
Set items can appear in a different order every time you use
them, and cannot be referred to by index or key.
Unchangeable
Set items are unchangeable, meaning that we cannot change
the items after the set has been created.
26
Duplicates Not Allowed
Sets cannot have two items with the same value.
Example
Duplicate values will be ignored:
thisset = {"apple", "banana", "cherry", "apple"}
print(thisset)
Get the Length of a Set
To determine how many items a set has, use
the len() function.
Example
Get the number of items in a set:
thisset = {"apple", "banana", "cherry"}
print(len(thisset))
Set Items - Data Types
Set items can be of any data type:
Example
String, int and boolean data types:
set1 = {"apple", "banana", "cherry"}
set2 = {1, 5, 7, 9, 3}
set3 = {True, False, False}
27
Python Dictionaries
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered*, changeable and
do not allow duplicates.
Dictionaries are written with curly brackets, and have keys and
values:
Example
Create and print a dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Dictionary Items
Dictionary items are ordered, changeable, and does not allow
duplicates.
Dictionary items are presented in key:value pairs, and can be
referred to by using the key name.
Example
Print the "brand" value of the dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"])
28
Changeable
Dictionaries are changeable, meaning that we can change, add
or remove items after the dictionary has been created.
Duplicates Not Allowed
Dictionaries cannot have two items with the same key:
Example
Duplicate values will overwrite existing values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020
}
print(thisdict)
Dictionary Length
To determine how many items a dictionary has, use
the len() function:
Example
Print the number of items in the dictionary:
print(len(thisdict))
29
Python - String Methods
Python has a set of built-in methods that you can use on
strings.
Note: All string methods return new values. They do not
change the original string.
Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a string
encode() Returns an encoded version of the string
endswith() Returns true if the string ends with the specified value
expandtabs() Sets the tab size of the string
find() Searches the string for a specified value and returns the position of
where it was found
30
isprintable() Returns True if all characters in the string are printable
isspace() Returns True if all characters in the string are whitespaces
istitle() Returns True if the string follows the rules of a title
isupper() Returns True if all characters in the string are upper case
join() Joins the elements of an iterable to the end of the string
ljust() Returns a left justified version of the string
lower() Converts a string into lower case
lstrip() Returns a left trim version of the string
maketrans() Returns a translation table to be used in translations
partition() Returns a tuple where the string is parted into three parts
replace() Returns a string where a specified value is replaced with a specified
value
31
rfind() Searches the string for a specified value and returns the last position of
where it was found
rindex() Searches the string for a specified value and returns the last position of
where it was found
rjust() Returns a right justified version of the string
rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list
rstrip() Returns a right trim version of the string
split() Splits the string at the specified separator, and returns a list
splitlines() Splits the string at line breaks and returns a list
startswith() Returns true if the string starts with the specified value
strip() Returns a trimmed version of the string
swapcase() Swaps cases, lower case becomes upper case and vice versa
32
Python Operators
Operators are used to perform operations on variables and
values.
In the example below, we use the + operator to add together
two values:
Example
print(10 + 5)
Python divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
33
Python Booleans
Booleans represent one of two values: True or False.
Boolean Values
In programming you often need to know if an expression
is True or False.
You can evaluate any expression in Python, and get one of two
answers, True or False.
When you compare two values, the expression is evaluated and
Python returns the Boolean answer:
Example
print(10 > 9)
print(10 == 9)
print(10 < 9)
When you run a condition in an if statement, Python
returns True or False:
Example
Print a message based on whether the condition is True or False:
a = 200
b = 33
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
34
Python If ... Else
Python Conditions and If statements:
Python supports the usual logical conditions from mathematics:
Equals: a == b
Not Equals: a != b
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
These conditions can be used in several ways, most commonly
in "if statements" and loops.
An "if statement" is written by using the if keyword.
Example
If statement:
a = 33
b = 200
if b > a:
print("b is greater than a")
Elif Statements:
The elif keyword is Python's way of saying "if the previous
conditions were not true, then try this condition".
Example
a = 33
b = 33
if b > a:
35
print("b is greater than a")
elif a == b:
print("a and b are equal")
Else Statements:
The else keyword catches anything which isn't caught by the
preceding conditions.
Example
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
36
Python Loops
Python has two primitive loop commands:
while loops
for loops
The while Loop:
With the while loop we can execute a set of statements as long
as a condition is true.
Example
Print i as long as i is less than 6:
i = 1
while i < 6:
print(i)
i += 1
Note: remember to increment i, or else the loop will continue
forever.
The while loop requires relevant variables to be ready, in this
example we need to define an indexing variable, i, which we
set to 1.
37
For Loops:
A for loop is used for iterating over a sequence (that is either a
list, a tuple, a dictionary, a set, or a string).
This is less like the for keyword in other programming
languages, and works more like an iterator method as found in
other object-orientated programming languages.
With the for loop we can execute a set of statements, once for
each item in a list, tuple, set etc.
Example
Print each fruit in a fruit list:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
The range() Function:
To loop through a set of code a specified number of times, we
can use the range() function,
The range() function returns a sequence of numbers, starting
from 0 by default, and increments by 1 (by default), and ends
at a specified number.
Example
Using the range() function:
for x in range(6):
print(x)
38
Python Functions
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
Creating a Function:
In Python a function is defined using the def keyword:
Example
def my_function():
print("Hello from a function")
Calling a Function:
To call a function, use the function name followed by
parenthesis:
Example
def my_function():
print("Hello from a function")
my_function()
Arguments:
Information can be passed into functions as arguments.
39
Arguments are specified after the function name, inside the
parentheses. You can add as many arguments as you want,
just separate them with a comma.
Example
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
40
Python Lambda Function
A lambda function is a small anonymous function.
A lambda function can take any number of arguments, but can
only have one expression.
Syntax:
lambda arguments : expression
The expression is executed and the result is returned:
Example
Add 10 to argument a, and return the result:
x = lambda a : a + 10
print(x(5))
Lambda functions can take any number of arguments:
Example
Multiply argument a with argument b and return the result:
x = lambda a, b : a * b
print(x(5, 6))
Why Use Lambda Functions?
The power of lambda is better shown when you use them as an
anonymous function inside another function.
Say you have a function definition that takes one argument,
and that argument will be multiplied with an unknown number:
41
def myfunc(n):
return lambda a : a * n
Use that function definition to make a function that always
doubles the number you send in:
Example
def myfunc(n):
return lambda a : a * n
mydoubler = myfunc(2)
print(mydoubler(11))
42
CONCLUSIONS
Practical knowledge means the visualization of the knowledge ,which we read
in our books. For this, we perform experiments and observations. Practical
knowledge is very important in every field. One must be familiar with the
problems related to that field so that he may solve them and become a
successful person.
After achieving the proper goal in life , an engineer has to enter in professional
life. According to this life, he has to serve an industry , may be public or private
sector or self-own. For the efficient work in the field, he must be well aware of
the practical knowledge as well as theoretical knowledge.
Due to all above reasons and to bridge the gap between theory and practical,
our Engineering curriculum provides a practical training of 30 days. During this
period a student work in the industry and get well all type of experience and
knowledge about the working of companies and hardware and software tools.
I have undergone my 30 days summer training in 5th sem at GICT. This report is
based on the knowledge , which I acquired during my 30 days of summer
training.
43
References
a. www.w3schools.com/python/
b. www.python.org
44
MAJOR PEOJECT ON CHATBOT
To make this project we use HTML, JAVASCRIPT,CSS, and PYTHON.
We make this code with the help of VS code software and to performing chatbot in
HTML page we use localhost.
JavaScript:
HTML and PYTHON Command:
45
CSS:
46
47
BOT Command:
OUTPUT:
48