You are on page 1of 28

“Python”

An internship Report Submitted


in partial fulfillment for the award of
Bachelor of Technology in Electronic & Communication
Engineering
Submitted to
RAJIV GANDHI PROUDYOGIKI VISHWAVIDYALAYA
BHOPAL (M.P.)

Submitted by

OM TIWARI (0301EC211030)
Under the supervision of mr. Anirudh Singh

Rewa Engineering College , Rewa


(M.P.)
Session:-2023
Acknowledgment
I would like to take this opportunity to express my sincere gratitude to all those who have helped me
during my Python internship at CAD SOFT ENGINEER. This internship has been a valuable
learning experience, and I could not have accomplished it without the support and guidance of many
individuals and groups.

First and foremost, I would like to extend my deepest appreciation to Mr. Pawan Mishra , my mentor
throughout this internship. He provided me with invaluable insights into Python programming and
software development practices. His mentorship and constant feedback played a crucial role in my
professional growth.

I would like to thank the entire team for their welcoming and collaborative work environment. The
camaraderie and willingness to share knowledge among the team members made this internship a
truly enriching experience.

I am also grateful to my colleagues and fellow interns who were always ready to brainstorm and
troubleshoot together. Your camaraderie made the work atmosphere enjoyable and motivating.

I would like to acknowledge the guidance and support of my professors and academic advisors from
Rewa Engineering college . Their encouragement and belief in my abilities inspired me to pursue this
internship opportunity.

OM TIWARI

25-10-2023
Declaration
I, Om Tiwari, hereby declare that the Python internship report titled "python " is an original work
undertaken by me during my internship at Cad Soft Engineer , located at Rewa M.P., from 14-07-
2023 to 27-07-2023.

I further declare that this report represents my own efforts, research, and observations during the
internship period. Any external sources, references, or materials used in this report have been
properly cited and acknowledged according to the standard academic and ethical guidelines. All code
snippets, scripts, and software developed or utilized during the internship have been appropriately
documented and attributed.

I affirm that no part of this report has been submitted in any other academic or professional context
for evaluation, and I have not received any form of assistance or collaboration that would
compromise the originality and authenticity of this work, except where explicitly mentioned and
cited.

I understand that any violation of academic or professional ethics, including plagiarism or


misrepresentation of work, is a serious offense, and I am fully responsible for the content presented
in this report.

Date: 06-10-2023
Om Tiwari
CONTENT
 Introduction
 Features of Python
 Usage of Python
 Getting Started with Python
 Variables
 Datatypes
 Operators
 If statement
 If-else statement
 Loops
 Jump statement
 List in python
 Set in python
 Tuple in python
 Dictionary in python
 Function in python
 Class and objects
 Tkinter GUI
Introduction to Python
Python is a high-level, open-source programming language that is easy to learn and use. Its simple
syntax and dynamic semantics make it popular among developers, educators, and researchers alike.

Python is widely used in various fields such as web development, data analysis, artificial
intelligence, machine learning, and scientific computing. Its versatility and flexibility make it
possible to handle various programming tasks.

Python has a large and active community, which provides excellent support and resources for
beginners and experts alike. There are also many third-party libraries and frameworks available that
can help you build complex applications quickly and easily.

If you're new to programming, Python is an excellent language to start with. Its easy-to-learn syntax,
rich libraries, and active community make it a great choice for beginners. And if you have experience
in other languages, Python is still worth learning because of its versatility and flexibility.

In conclusion, Python is a powerful language that has gained immense popularity in recent years. Its
simple syntax, dynamic semantics, and large community make it a perfect choice for beginners and
experts alike.

1. Python is a high-level, open-source programming language that is easy to learn and use.

2. Python's simple syntax and dynamic semantics make it popular among developers, educators, and
researchers alike.

3. Python is widely used in various fields such as web development, data analysis, artificial
intelligence, machine learning, and scientific computing.

4. Python's versatility and flexibility make it possible to handle various programming tasks.

5. Python has a large and active community that provides excellent support and resources for
beginners and experts alike.

6. There are also many third-party libraries and frameworks available that can help you build
complex applications quickly and easily.

7. If you're new to programming, Python is an excellent language to start with because of its easy-to-
learn syntax, rich libraries, and active community.

8. And if you have experience in other languages, Python is still worth learning because of its
versatility and flexibility.
Features of Python
Interpreted Language

Python is an interpreted programming language, which means that code written in it is executed
directly by the Python interpreter. When a Python program is run, the interpreter reads the Python
code that you have written, translates it into machine instructions, and then executes those
instructions on the computer.

Object-oriented programming support

Python is an object-oriented programming language. This means that the language supports objects
that combine data and methods/functions that can operate on that data. This makes it easier to
organize and structure code, making it more reusable and easier to maintain.

Dynamic typing

Python is dynamically typed. This means that the type of a variable is determined at runtime, rather
than at compile-time. This allows for flexibility and makes programming in Python faster and more
agile.

Extensive standard library

Python has an extensive standard library that provides a wide array of pre-built modules and
packages that can be used to perform a variety of tasks. This makes it easy to perform common
programming tasks without having to write code from scratch.

Web Development

Web development refers to the creation, updating and maintenance of websites and web applications.
It involves working with different web technologies such as HTML, CSS, JavaScript, and web
frameworks to build user-friendly and responsive websites.

Data Analysis and Visualization

Data analysis and visualization involves extracting insights from data through statistical and
computational methods and presenting the information in a visually appealing way. The process
involves data cleaning, exploration, modeling, and communication of findings through static and
interactive visualizations.

Game Development

Game development involves the creation of video games for different platforms such as consoles,
mobile devices, and desktop computers. It involves working with game engines, programming
languages, 3D modeling, and animation tools to create engaging and immersive experiences for
players.

Installing Python and IDE


To begin, you need to install Python on your computer. You can download the latest version of
Python from the official website, choose the appropriate version for your operating system. After
downloading, follow the installation wizard to complete the installation process.

Once you have installed Python, you need to choose and install an Integrated Development
Environment (IDE) or code editor. Some popular options include PyCharm, Visual Studio Code, and
Sublime Text. Each has its own set of features and functionalities that you can explore.

Installing PyCharm is relatively easy. You can download the community edition from their website
or use the JetBrains Toolbox app. Installation instructions are included in the wizard.

To Install Visual Studio Code, download the installer from their website, run it, and follow the
instructions.

Installing Sublime Text involves downloading the installer from their website and following the
instructions in the wizard.

These are the basic steps to install Python and an IDE. With these tools, you can start coding your
Python programs and explore the vast array of possibilities this language offers.
Python Variables
A variable is a fundamental concept in any programming language. It is a reserved memory location
that stores and manipulates data. This tutorial on Python variables will help you learn more about
what they are, the different data types of variables, the rules for naming variables in Python. You will
also perform some basic operations on numbers and strings. We’ll use Jupyter Notebook to
implement the Python codes.

Variables are entities of a program that holds a value. Here is an example of a variable:

x=100

In the below diagram, the box holds a value of 100 and is named as x. Therefore, the variable is x,
and the data it holds is the value.

The data type for a variable is the type of data it holds. In the above example, x is holding 100,
which is a number, and the data type of x is a number.In Python, there are three types of
numbers: Integer, Float, and Complex.Integers are numbers without decimal points. Floats are
numbers with decimal points. Complex numbers have real parts and imaginary parts.

Another data type that is very different from a number is called a string, which is a collection of
characters.

Let’s see a variable with an integer data type:

x=100

To check the data type of x, use the type() function:

type(x)
Data Types
Python has its own built-in data types, and t hey are listed below:

str (Text Type)

int, float, complex (Numeric Type)

list, tuple (Sequence Type)

dict (Mapping Type)

set (Set Type)

bool (Boolean Type)

bytes, bytearray, memoryview (Binary Types)

These data types are nothing but classes in Python, as mentioned earlier.

Identify Data Types in Python

Programmers can use type keywords to identify the data type of the variable. The syntax is type
(variable).

Let us see a couple of examples of how to identify the data type of variable in Python.

Program for type function


Output

Now, let’s get a deeper understanding of the Python data types.

String data type in Python

A string is defined as a collection of Unicode characters. A string in Python can be defined using
single quotes or double quotes, that is ‘Test String’ and ‘’Test String” are the same.

You will now see a quick example for string data type in Python. In this example, make sure to use
the print() function to display the string in Python.

Program for String

Output
You have seen how to define strings using single quotes and double-quotes. All good, but in case
you want to display a multiline string, any idea how can that be achieved?

Multiline strings are supported in Python using triple quotes. We can use either triple single quote ‘ ‘
‘ or triple double quotes “ “ “ to denote a multiline string.

Python Operators
The special symbols in Python to perform arithmetic operations, comparison operations, logical
operations, bitwise operations, assignment operations, identity operations, and membership
operations on variables and values, are called operators in Python. The value on which the operation
is being performed is called an operand in Python.

Arithmetic Operators in Python:

Arithmetic operators are used, to perform arithmetic operations on numerical values. The arithmetic
operators in Python are:

The arithmetic operator + is used for addition.

The arithmetic operator – is used for subtraction.

The arithmetic operator * is used for multiplication.

The arithmetic operator / is used to perform division.

The arithmetic operator % is used for finding the modulus.

The arithmetic operator ** is used for exponentiation.

The arithmetic operator // is used for floor division.

Assignment Operators in Python:


Assignment operators in Python assign the right-hand side values to the operand that is present on
the left-hand side. The assignment operators in Python is used as the "=" symbol. We have different
types of assignment operators like +=, -=, \*=, %=, /=, //=, \*\*=, &=, |=, ^=, >>=, <<=.

Comparison Operators in Python: Comparison or relational operators in Python


are used to compare variables with values.
The comparison operator comes in between the left and right variables or operands. It
simply tells us the relationship between the two.
Comparison operators in python include:

 Equal to ==
 Not equal to !=
 Greater than >
 Less than <
 Greater than or equal to >=
 Less than or equal to <=

Logical Operators in Python:

Logical operators, as the name indicates are used to perform logical operations. The logical operators
are:

AND operation returns true if both the operands are true.

OR operation returns true if one of the operands is true.

NOT operation returns true if the operand is false.

Membership Operators in Python:

The presence of an element in the sequence can be checked using membership operators. The
membership operators are:

In- Returns true if the variable is present in the specified sequence.

Not in - Returns true if the variable is not present in the specified sequence.

If-Else Statement
The if-else statement is used to execute both the true part and the false part of a given condition. If
the condition is true, the if block code is executed and if the condition is false, the else block code is
executed.

Syntax:

if(condition):

#Executes this block if the condition is true

else:

#Executes this block if the condition is false

You should note here that Python uses indentation in both the blocks to define the scope of the code.
Other programming languages often use curly brackets for this purpose.

Below is the entire workflow of how the if-else statement works.

First, the test expression is checked. If it is true, the statements present in the body of the if block
will execute. Next, the statements present below the if block is executed. In case the test expression
has false results, the statements present in the else body are executed, and then the statements below
the if-else are executed.
The following is an example that better illustrates how if-else works:

Since the value of “i” is divisible by two, the if statement is executed.

Since the value of “i” is not divisible by two, the else statement is executed.

Loops in python
A loop is an instruction that repeats multiple times as long as some condition is met.

Flowchart:
Fig: Flowchart of Python loop

Significance of indentation- Indentation is significant in Python. It is used to define a block of


code; without indentation, the program will show an error.

Type of Loops

There are mainly two types of loops. Let’s discuss them one by one.

1. For Loop
A for loop in Python is used to iterate over a sequence (list, tuple, set, dictionary, and string).

Flowchart:
Fig: Flowchart of a for loop

Syntax: for iterating_var in sequence:

statement(s)

2. While Loop

The while loop is used to execute a set of statements as long as a condition is true.

Flowchart:

Fig: While loop flowchart

Syntax: while expression:

statements

3. Nested Loop

If a loop exists inside the body of another loop, it is called a nested loop.

The preceding code executes as follows: The program first encounters the outer loop, performing its
first iteration. This first iteration triggers the inner, nested loop, which then runs to completion. Then
the program returns to the top of the outer loop, completing the and again triggers the nested loop.
Break in Python

The syntax is as follows:

break;

It is used after the loop statements.

Flowchart of Break in Python

The following flowchart shows the use and control flow of a break statement in a loop.

Using Break in Python

Since it is now clear what a break statement is, it’s time to look at some examples and understand
how to use them. In each instance, you will be using Break in Python with different loops.

Using Break in While Loop

As you can see in the example above, there is a defined integer n with the value 0. Then, there is a
defined while loop for printing the value of n and increasing it by one after each iteration. Next, you
saw how it defined a condition for the break statement, which is when n becomes 5. When the
condition is met, the break statement terminates the loop, and the control goes to the next statement,
which is the print statement.
Python List
A Python list is a collection of zero or more elements. An element of the list can be any data. It can
be string, numerical, or a combination of both types. A list in Python is like an array in C or Java.
Lists are mutable- that is, you can change their content-and they have many useful specialized
methods.

A Python list is created by adding elements in the square brackets [ ].

For example:

num = [1, 2, 3, 4]

letter = [‘a’, ‘b’, ‘c’, ‘d’]

Fig: Create the Python List

These lists can contain elements of different types.

Creating a Python List

A list is created in PythonPython by placing items inside [], separated by commas. A list can have
any number of things; they can be of different types (integer, float, string, etc.).

1. Access in Python list: Each item in a list is related to a number. The number is known as the list
index. It accesses elements of an array using the index number (0, 1, 2, 3 …).
2. Negative Indexing in PythonPython: Python allows negative indexing for sequences. If the
specified index does not, it shows the "Index Error" exception.
3. Slicing in Python list: In Python, it is possible to access a section of items from the List using the
slicing operator ":" not just a single item.

Just note that when we slice lists, the start index is inclusive, but the end index is exclusive.
Access Elements From List

Every Python list starts with the index ‘0’. We can access the elements by specifying the index
number. For example: To access elements in the list, we provide the index (as integer) inside the
square brackets ( [ ] ) as given below.

Fig: Access elements from starting of the list

To access the elements from the end we use negative indexing. -1 means the last element. -2 the
second last element and so on. For instance, if you want to access the 4th element from the ending of
the list named mix, you write mix[-4].

1. Using the Append() Method

The append() method adds the element to the end of the list. For example:

2. Using the Insert() Method

If you want to insert an element at a specific index, you should use the insert () method.

3. Delete Specified Elements We Use Remove() Method.

Suppose you want to delete the item “get” from the list “mix”. We write it as mix.remove(“get”).

4. To Remove the Element From Specific Index We Use Del() Method

Syntax: del list_name [index]


Check the Length of the List

You can check the number of items in the list by using ‘len ()’ method

Code:

Mix=[1,6,’python’,’programming’]

Print(len(mix));

To Join the Two List

There are several ways to join two lists, and the easiest method is to use the ‘ + ‘ operator. This can
be done in the following way:
SET IN PYTHON
Set is a data type in python used to store several items in a single variable. It is one of the four built-
in data types (List, Dictionary, Tuple, and Set) having qualities and usage different from the other
three. It is a collection that is written with curly brackets and is both unindexed and unordered.

A set is mutable, i.e., we can remove or add elements to it. Set in python is similar to mathematical
sets, and operations like intersection, union, symmetric difference, and more can be applied.

Set Items

Items of a set in python are immutable (unchangeable), do not duplicate values, and unordered. Thus,
items in a set do not appear in a stipulated manner, i.e., they can appear in a different order every
time it is used. Due to this, set items cannot be referred to by key or index.

Set items can be of any data type: String, Boolean, tuple, float, int.

set1 = {"ab", "bc", "cd"}

set2 = {11, 15, 17, 19, 13}

set3 = {False, False, True}

How to Create a Set in Python

To create a python set, place all elements or items separated by a comma inside curly braces {}. The
built-in set() function can also be used to create a set in python. As per definition, a set can have any
number and any items. However, mutable elements such as dictionaries, lists, or sets are not allowed
as its elements.

integer = {11, 12, 23}

print(integer)

# Mixed set

mixed = {10.0, "Hi", (11, 12, 13)}

print(mixed)

Output: (Notice the random order)


Python Tuples
A Python tuple is an immutable ordered sequence of items. In other words, existing objects in the
sequence cannot be modified, and new elements cannot be added once the sequence is created. A
tuple consists of several values separated by commas. Unlike a Python list, tuples are enclosed
within parentheses “( )”.

Create a Python Tuple

A Python tuple is created by using parentheses separated by commas. A tuple can hold multiple data
types.

Syntax: tuple_name = (“element1”, “element2”, “element3”)

Nested Python Tuples

We can also nest a tuple or a list inside a Python tuple. The below-mentioned example illustrates
this.

Example:

Access Items From a Tuple

We can access a tuple’s elements by referring to the index number. Remember that the index in a
Python tuple starts from ‘0’. To access elements in a tuple, we provide the index (as integer) inside
the square brackets ( [ ] ), as shown below.
Dictionary In python
A dictionary is a kind of data structure that stores items in key-value pairs. A key is a unique
identifier for an item, and a value is the data associated with that key. Dictionaries often store
information such as words and definitions, but they can be used for much more. Dictionaries are
mutable in Python, which means they can be changed after they are created. They are also unordered,
indicating the items in a dictionary are not stored in any particular order.

Creating a Dictionary

Dictionaries are created using curly braces {}. The key is on the left side of the colon (:) and the
value is on the right. A comma separates each key-value pair. Creating a Python dictionary is
straightforward. Remember to use curly braces {} and separate each key-value pair with a comma.

You will use the built-in dictionary data type to create a Python dictionary. This type stores all kinds
of data, from integers to strings to lists. The dictionary data type is similar to a list but uses keys
instead of indexes to look up values.

You use the dict() function in Python to create a dictionary. This function takes two arguments:

The first argument is a list of keys.

The second argument is a list of values.

Check out the example of how to create a dictionary using the dict() function:

# empty dictionary
my_dict = {}
# dictionary with integer keys
my_dict = {1: 'apple', 2: 'ball'}
# dictionary with mixed keys
my_dict = {'name': 'John', 1: [2, 4, 3]}
# using dict()
my_dict = dict({1:'apple', 2:'ball'})
# from sequence having each item as a pair
my_dict = dict([(1,'apple'), (2,'ball')])

Accessing Elements of a Dictionary

In Python, dictionaries are accessed by key, not by index. This means you can't access a dictionary
element by using its position in the dictionary. Instead, you must use the dictionary key.
The second way to access a dictionary element is using the [] operator. This operator takes the
dictionary key as an argument and returns the value associated with the key value. If the key value is
not in the dictionary, the [] operator will raise a KeyError.

# get vs [] for retrieving elements


my_dict = {'name': 'Jack', 'age': 26}
# Output: Jack
print(my_dict['name'])
# Output: 26
print(my_dict.get('age'))
# Trying to access keys that don't exist throws an error
# Output None
print(my_dict.get('address'))
# KeyError
print(my_dict['address'])

Methods

In Python, several built-in methods allow us to manipulate dictionaries. These methods are useful for
adding, removing, and changing the values of dictionary keys. Dictionary methods are a powerful
way to work with dictionaries. By understanding how these methods work, we can more effectively
use dictionaries to store and manipulate data.

Method Description

clear() Removes all the elements from the dictionary

copy() Returns a copy of the dictionary

get() Returns specified key value


items() Returns an index having a tuple for every key-value pair

keys() Returns a list containing the dictionary's keys

pop() Removes the element with the specified key

popitem() Remove last inserted key-value pair

Python Functions
A function is a set of code that performs any given task, enabling the programmer to modularize a
program. All variables created in function definitions are local variables; they are known only to the
function in which they are declared.

How to Create and Call a Function

In Python, you create a function by using the def keyword. Let’s look at an example of this.

Syntax: def name(arguments):

Statement

return value

Example:

The def keyword only creates and defines a function. To call the function, use the function name,
followed by parentheses.
Example:

Arguments in a Python Function

You can send information to a function by passing values, which are known as arguments or
parameters. They are mentioned after the function name inside the parentheses. You can add as many
arguments you’d like by separating them with a comma.

Example:
Class
The class can be defined as a collection of objects that define the common attributes and behaviors of
all the objects. To sum up, it can be called a blueprint of similar objects.

For better understanding, let’s go through an example. In this case, we are considering a Person as a
class. Now, if a person is a class, every person has certain features, such as name, gender, and age.
Every person has certain behaviors, they can talk, walk, run, or vote.

Class is defined under a “class” keyword.

Object
Just like everything in the real world is an object, so is the case with the OOPS programming
paradigm.

The object is an entity that has state and behavior. It is an instance of a class that can access the data.

Example:
Fig: Defining an object

The _init_Method

The _init_ method is run as soon as an object of a class is created. This method is useful for passing
initial value to your objects.

Fig: _init_ method

“Self” represents the instance of the class. It binds the attributes to the given arguments.

Creating Classes and Objects in Python

Fig: Creating class and objects

Here, emp1 and emp2 are objects of the class employee.

You might also like