Python Report File
Python Report File
KASHIPUR
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.
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.
4
Good to know
5
Python Getting Started
Python Install
Many PCs and Macs will have python already installed.
python --version
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:
Let's write our first Python file, called helloworld.py, which can
be done in any text editor.
6
helloworld.py
print("Hello, World!")
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
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
8
Example
#This is a comment
#written in
#more than just one line
print("Hello, World!")
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
Example
x = 5
y = "John"
print(x)
print(y)
Example
x = 4 # x is of type int
x = "Sally" # x is now of type str
print(x)
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
Example
x = 5
y = "John"
print(type(x))
print(type(y))
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:
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"
12
Example
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Example
x = y = z = "Orange"
print(x)
print(y)
print(z)
13
Python Data Types
In programming, data type is an important concept.
14
Example
Print the data type of the variable x:
x = 5
print(type(x))
If you want to specify the data type, you can use the following
constructor functions:
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = range(6) range
15
Python Numbers
There are three numeric types in Python:
int
float
complex
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
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.
Example
print("Hello")
print('Hello')
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)
Example
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)
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.
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:
List Length
To determine how many items a list has, use
the len() function:
Example
Print the number of items in the list:
Example
String, int and boolean data types:
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.
Example
Create a Tuple:
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:
Tuple Length
To determine how many items a tuple has, use the len() function:
Example
Print the number of items in the tuple:
Example
String, int and boolean data types:
Example
A tuple with strings, integers and boolean values:
25
Python Sets
Sets are used to store multiple items in a single variable.
Example
Create a Set:
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:
print(thisset)
Example
Get the number of items in a set:
print(len(thisset))
Example
String, int and boolean data types:
27
Python Dictionaries
Dictionaries are used to store data values in key:value pairs.
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.
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.
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.
Method Description
endswith() Returns true if the string ends with the specified value
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
isupper() Returns True if all characters in the string are upper case
partition() Returns a tuple where the string is parted into three parts
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
rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list
split() Splits the string at the specified separator, and returns a list
startswith() Returns true if the string starts with the specified value
swapcase() Swaps cases, lower case becomes upper case and vice versa
32
Python Operators
Operators are used to perform operations on variables and
values.
Example
print(10 + 5)
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
You can evaluate any expression in Python, and get one of two
answers, True or False.
Example
print(10 > 9)
print(10 == 9)
print(10 < 9)
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:
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
Example
If statement:
a = 33
b = 200
if b > a:
print("b is greater than a")
Elif Statements:
Example
a = 33
b = 33
if b > a:
35
print("b is greater than a")
elif a == b:
Else Statements:
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
Example
Print i as long as i is less than 6:
i = 1
while i < 6:
print(i)
i += 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).
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:
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.
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.
Syntax:
lambda arguments : expression
Example
Add 10 to argument a, and return the result:
x = lambda a : a + 10
print(x(5))
Example
Multiply argument a with argument b and return the result:
x = lambda a, b : a * b
print(x(5, 6))
41
def myfunc(n):
return lambda a : a * n
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:
45
CSS:
46
47
BOT Command:
OUTPUT:
48