Professional Documents
Culture Documents
PYTHON PROGRAMMING
A
TRAINING REPORT SUBMITTED IN PARTIAL FULFILLMENT OF THE
REQUIREMENTS FOR THE AWARD OF DEGREE OF
BACHELOR OF TECHNOLOGY
IN
ELECTRICAL AND ELECTRONICS ENGINEERING
BY
GANTAKOLLA BHUVAN SHASHANK (21A91A0215)
Approved by AICTE, Permanently Affiliated to JNTUK & Accredited by NAAC with ‘A++’ Grade,
Accredited by NBA, Recognized by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Aditya Nagar, ADB Road – Surampalem – 533437, Kakinada Dist., A.P.,
2023-2024
Python Programming
INTERNSHIP LETTER
Student’s Declaration
By
(21A91A0215)
ACKNOWLEDGMENT
Training has an important role in exposing the real-life situation in an industry. It was a
great experience for me to work on training at TECHNICAL HUB through which I could learn
how to work in a professional environment. Now, I would like to thank the people who guided
me and have been a constant source of inspiration throughout the tenure of my internship
training.
CONTENTS
1 ACKNOWLEDGMENT 4
2 INTRODUCTION TO PYTHON 6
3 PYTHON OPERATORS 8
5 PYTHON LISTS 10
6 PYTHON DICTIONARY 13
7 PYTHON TUPLES 16
8 PYTHON SETS 18
9 PYTHON STRINGS 21
10 PYTHON LOOPS 24
12 CONCLUSION 28
INTRODUCTION TO PYTHON
History of Python
Python is a widely-used general-purpose, high-level programming language. It was initially
designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was
mainly developed for emphasis on code readability, and its syntax allows programmers to express
concepts in fewer lines of code.
In the late 1980s, history was about to be written. It was that time when working on Python
started. Soon after that, Guido Van Rossum began doing its application-based work in December of
1989 at Centrum Wickenden & Informatica (CWI) which is situated in the Netherlands. It was
started firstly as a hobby project because he was looking for an interesting project to keep him
occupied during Christmas.
What is python?
Python is a high-level scripting language which can be used for a wide variety of text processing,
system administration and internet-related tasks. Unlike many similar languages, its core language is
very small and easy to master, while allowing the addition of modules to perform a virtually limitless
variety of tasks. Python is a true object-oriented language, and is available on a wide variety of
platforms. There’s even a python interpreter written entirely in Java, further enhancing python’s
position as an excellent solution for internet-based problems.
Python was developed in the early 1990’s by Guido van Rossum, then at CWI in Amsterdam, and
currently at CNRI in Virginia. In some ways, python grew out of a project to design a computer
language which would be easy for beginners to learn, yet would be powerful enough for even
advanced users. This heritage is reflected in python’s small, clean syntax and the thoroughness of the
implementation of ideas like object-oriented programming, without eliminating the ability to program
in a more traditional style. So, python is an excellent choice as a first programming language without
sacrificing the power and advanced capabilities that users will eventually need.
Although pictures of snakes often appear on python books and websites, the name is derived
from Guido van Rossum’s favourite TV show, “Monty Python’s Flying Circus”. For this reason, lots
of online and print documentation for the language has a light and humorous touch. Interestingly,
many experienced programmers report that python has brought back a lot of the fun they used to have
programming, so van Rossum’s inspiration may be well expressed in the language itself.
Why Python?
The language’s core philosophy is summarized in the document The Zen of Python (PEP 20), which
includes aphorisms such as…
Python Operators
In Python programming, Operators in general are used to perform operations on values and
variables. These are standard symbols used for the purpose of logical and arithmetic operations. In
this article, we will look into different types of Python operators.
OPERATORS: These are the special symbols. E.g.- +, *, /, etc.
OPERAND: It is the value on which the operator is applied.
Types of Operators in Python
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Identity Operators and Membership Operators
Arithmetic Operators in Python:
Python Arithmetic operators are used to perform basic mathematical operations like addition,
subtraction, multiplication, and division.
> Greater than: True if the left operand is greater than the
x>y
right
< Less than: True if the left operand is less than the right x<y
>= Greater than or equal to: True if left operand is greater than
x >= y
or equal to the right
<= Less than or equal to: True if left operand is less than or
x <= y
equal to the right
In Python, Logical operators are used on conditional statements (either True or False). They
perform Logical AND, Logical OR and Logical NOT operations.
Data Structures are a way of organizing data so that it can be accessed more efficiently
depending upon the situation. Data Structures are fundamentals of any programming language
around which a program is built. Python helps to learn the fundamental of these data structures in a
simpler way as compared to other programming languages.
In this, we will discuss the Data Structures in the Python Programming Language and how they
are related to some specific Python Data Types. We will discuss all the in-built data structures like
list tuples, dictionaries, etc. as well as some advanced data structures like trees, graphs, etc.
PYTHON LISTS: -
A list is a data-structure, or it can be considered a container that can be used to store multiple data
at once. The list will be ordered and there will be a definite count of it. The elements are indexed
according to a sequence and the indexing is done with 0 as the first index. Each element will have a
distinct place in the sequence and if the same value occurs multiple times in the sequence, each will
be considered separate and distinct element. A more detailed description on lists and associated data-
types are covered in this tutorial.
In this tutorial you will come to know of the about how to create python lists and the common
paradigms for a python list.
Lists are great if you want to preserve the sequence of the data and then iterate over them later for
various purposes. We will cover iterations and for loops in our tutorials on for loops.
To create a list, you separate the elements with a comma and enclose them with a bracket “[]”.
For example, you can create a list of company names containing “hacker earth”, “google”,
“Facebook”. This will preserve the order of the names.
Trying to access elements outside the range will give an error. You can create a two-dimensional list.
This is done by nesting a list inside another list. For example, you can group “hacker earth” and
“Paytm” into one list and “tcs” and “cts” into another and group both the lists into another “master”
list.
list.remove(elem) – will search for the first occurrence of the element in the list and will then remove
it.
For example, if you have a list of languages with elements [‘haskell’, ‘clojure’, ‘apl’, ‘scala’,
‘F#’] and you want to remove scala, you can use the remove method.
>>> langs.remove(“scala”)
>>> print(langs)
[‘haskell’, ‘clojure’, ‘apl’, ‘F#’]
list.pop() – will remove the last element of the list. If the index is provided, then it will remove
the element at the particular index. For example, if you have a list [5, 4, 3, 1] and you apply the
method pop, it will return the last element 1 and the resulting list will not have it.
For example, if you have an unsorted list [4,3,5,1], you can sort it using the sort method.
For example, if you have a list [1, 3, 4, 5] and you need to reverse it, you can call the reverse method.
You use the function “len” to get the length of the list.
For example, if you have a list of companies [‘hackerearth’, ‘google’, ‘facebook’] and you want the
list length, you can use the len function.
If you use another function “enumerate” over a list, it gives us a nice construct to get both the
index and the value of the element in the list.
For example, you have the list of companies [‘hackerearth’, ‘google’, ‘facebook’] and you want the
index, along with the items in the list, you can use the enumerate function.
>>> # loop over the companies and print both the index as youll as the name.
>>> for indx, name in enumerate(companies):
... print(“Index is %s for company: %s” % (indx, name))
...
Index is 0 for company: hackerearth
Index is 1 for company: google
Index is 2 for company: facebook
In this example, you use the for loop. For loops are pretty common in all programming languages that
support procedural constructs. You can head over to A complete theoretical reference to loops in C to
have a deeper understanding of for loops. Also look at the tutorial on loops in Python in Python
Control Structures tutorial.
Similar to the sort method, you can also use the sorted function which also sorts the list. The
difference is that it returns the sorted list, while the sort method sorts the list in place. So this function
can be used when you want to preserve the original list as well.
PYTHON DICTIONARY: -
Dictionary in Python is a collection of keys values, used to store data values like a map, which,
unlike other data types which hold only a single value as an element.
Example of Dictionary in Python
Dictionary holds key:value pair. Key-Value is provided in the dictionary to make it more
optimized.
Creating a Dictionary: -
In Python, a dictionary can be created by placing a sequence of elements within curly {} braces,
separated by ‘comma’. Dictionary holds pairs of values, one being the Key and the other
corresponding pair element being its Key:value. Values in a dictionary can be of any data type and
can be duplicated, whereas keys can’t be repeated and must be immutable.
Note – Dictionary keys are case sensitive, the same name but different cases of Key will be treated
distinctly.
# Creating a Dictionary
# with Integer Keys
Dict = {1: ‘Geeks’, 2: ‘For’, 3: ‘Geeks’}
print(“\nDictionary with the use of Integer Keys: “)
print(Dict)
# Creating a Dictionary
# with Mixed keys
Dict = {‘Name’: ‘Geeks’, 1: [1, 2, 3, 4]}
print(“\nDictionary with the use of Mixed Keys: “)
print(Dict)
Output:
Dictionary with the use of Integer Keys:
Dictionary can also be created by the built-in function dict(). An empty dictionary can be created
by just placing to curly braces{}.
Nested Dictionary: -
Addition of elements can be done in multiple ways. One value at a time can be added to a
Dictionary by defining value along with the key e.g. Dict[Key] = ‘Value’. Updating an
existing value in a Dictionary can be done by using the built-in update() method. Nested
key values can also be added to an existing Dictionary.
Note- While adding a value, if the key-value already exists, the value gets updated
otherwise a new Key with the value is added to the Dictionary.
Complexities for Adding elements in a Dictionary:
Time complexity: O(1)/O(n)
Space complexity: O(1)
Accessing elements of a Dictionary: -
In order to access the items of a dictionary refer to its key name. Key can be used inside square
brackets.
There is also a method called get() that will also help in accessing the element from a dictionary.
This method accepts key as argument and returns the value.
Dictionary methods: -
Method Description
PYTHON TUPLES: -
Python Tuple is a collection of objects separated by commas. In some ways, a tuple is similar
to a Python list in terms of indexing, nested objects, and repetition but the main difference between
both is Python tuple is immutable, unlike the Python list which is mutable.
Creating Python Tuples
There are various ways by which you can create a tuple in Python. They are as follows:
Using round brackets
With one item
Tuple Constructor
Create Tuples using Round Brackets ()
To create a tuple, we will use () operators.
What is Immutable in Tuples?
Tuples in Python are similar to Python lists but not entirely. Tuples are immutable and ordered and
allow duplicate values. Some Characteristics of Tuples in Python.
We can find items in a tuple since finding any item does not make changes in the tuple.
One cannot add items to a tuple once it is created.
Tuples cannot be appended or extended.
We cannot remove items from a tuple once it is created.
Accessing Values in Python Tuples: -
Tuples in Python provide two ways by which we can access the elements of a tuple.
Using a positive index
Using a negative index
Python Access Tuple using a Positive Index
Using square brackets, we can get the values from tuples in Python.
Access Tuple using Negative Index
In the above methods, we use the positive index to access the value in Python, and here we will use
the negative index within [].
Different Operations Related to Tuples:-
Below are the different operations related to tuples in Python:
Concatenation
Nesting
Repetition
Slicing
Deleting
Finding the length
Tuples in a Loop
PYTHON SETS: -
A Set in Python programming is an unordered collection data type that is iterable, mutable and has
no duplicate elements.
Set is represented by { } (values enclosed in curly braces)
The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for
checking whether a specific element is contained in the set. This is based on a data structure known
as a hash table. Since sets are unordered, we cannot access items using indexes as we do in lists.
Python Frozen Sets
Frozen sets in Python are immutable objects that only support methods and operators that produce
a result without affecting the frozen set or sets to which they are applied. It can be done with frozen
set () method in Python.
While elements of a set can be modified at any time, elements of the frozen set remain the same
after creation.
In, Python Sets are implemented using a dictionary with dummy variables, where key beings the
members set with greater optimizations to the time complexity.
Set Implementation:
x in s O(1) O(n)
Multiple
(n-1)*O(l) where l is
intersection
max(len(s1),..,len(sn))
s1&s2&..&sn
Operators Notes
s1 == s2 s1 is equivalent to s2
s1 != s2 s1 is not equivalent to s2
s1 <= s2 s1 is subset of s2
s1 >= s2 s1 is superset of s2
PYTHON STRINGS: -
A String is a data structure in Python that represents a sequence of characters. It is an immutable data
type, meaning that once you have created a string, you cannot change it. Strings are used widely in
many different applications, such as storing and manipulating text data, representing names, addresses,
and other types of data that can be represented as text.
String Slicing
In Python, the String Slicing method is used to access a range of characters in the String. Slicing in
a String is done by using a Slicing operator, i.e., a colon . One thing to keep in mind while using
this method is that the string returned after slicing includes the character at the start index but not
the character at the last index.
Example:
In this example, we will use the string-slicing method to extract a substring of the original string.
The [3:12] indicates that the string slicing will start from the 3 rd index of the string to the 12 th index,
(12th character not including). We can also use negative indexing in string slicing.
String.endswith() Returns True if a string ends with the given suffix otherwise
returns False
PYTHON LOOPS: -
Python Programming language provides the following types of loops to handle looping
requirements. Python provides three ways for executing the loops. While all the ways provide
similar basic functionality, they differ in their syntax and condition-checking time.
statement(s)
All the statements indented by the same number of character spaces after a programming construct
are considered to be part of a single block of code. Python uses indentation as its method of
grouping statements.
else:
statements(s)
Example with List, Tuple, string, and dictionary iteration using For Loops in Python
We can use for loop to iterate lists, tuples, strings and dictionaries in Python
We can also use the index of elements in the sequence to iterate. The key idea is to first calculate
the length of the list and in iterate over the sequence within the range of this length.
Nested Loops
Python programming language allows to use one loop inside another loop. Following section shows
few examples to illustrate the concept.
Syntax:
for iterator_var in sequence:
statements(s)
statements(s)
The syntax for a nested while loop statement in the Python programming language is as follows:
while expression:
while expression:
statement(s)
statement(s)
A final note on loop nesting is that we can put any type of loop inside of any other type of loop. For
example, a for loop can be inside a while loop or vice versa.
Continue Statement
the continue statement in Python returns the control to the beginning of the loop.
Break Statement
The break statement in Python brings control out of the loop.
Pass Statement
We use pass statement in Python to write empty loops. Pass is also used for empty control
statements, functions and classes.
How for loop in Python works internally?
Before proceeding to this section, you should have a prior understanding of Python Iterators.
Here we can see the for loops iterates over iterable object fruit which is a list. Lists, sets,
dictionaries are few iterable objects while an integer object is not an iterable object. For loops can
iterate over any of these iterable objects.
Now with the help of the above example, let’s dive deep and see what happens internally here.
1. Make the list (iterable) an iterable object with help of the iter() function.
2. Run an infinite while loop and break only if the StopIteration is raised.
3. In the try block, we fetch the next element of fruits with the next() function.
4. After fetching the element we did the operation to be performed with the element. (i.e
print(fruit))
Technical Hub is a Training institute which is part of Aditya Engineering College (A) located in
Aditya Educational Institutions at Surampalem. East Godavari in Andhra Pradesh 533437 India. It is
a specialized training centre which makes many of the Aditya Institutes students to learn various
technologies of computer, cloud services.
Babji Neelam is the C.E.O of the Technical Hub flatform who taken the idea to initiate a training
institute in Aditya Educational Institution at Surampalem.
In the year 2018 Babji Neelam initiated the idea of forming a training institute in Aditya Educational
Institutions, Surampalem. With a specialized incubation centre containing many facilities for the
students like high-speed internet connection, centralized Airconditioning and large class rooms with
many more features.
Technical hub is the one of the important flatform in providing software training for various roles in
software sector like coding, cloud services and web development. It is prestigious industry in that
sector. It is a good flatform and opportunity to students for learning various courses.
CONCLUSION
This report gives the basic details of Technical Hub and different services provided by it. Mainly
Python Programming and its features are explained precisely. Python Programming plays an
important role in writing complicated codes. Python is noting but a programming language. This
report also includes both the major and minor concepts of Python programming.
In any internship, the goal is to learn something new. I can say that this is an understatement for my
summer internship program on Python programming at Technical Hub. While learning this I was able
to apply my previous experiences and knowledge that I have learned in the classroom and apply it to
real-world experience.
Understanding the syntax of Python is great and all, and Python by itself is indeed a great language,
but the fundamentals of Python aren't why Python is a successful language. There are plenty of fun-
to-write languages that are just like Python, such as Ruby, Julia, even R. What makes Python the
victor is the community and 3rd-party packages. While we can do a lot with just an installation of
Python and the standard library, we can do infinitely more with all of the 3rd party libraries out here.