0% found this document useful (0 votes)
14 views19 pages

Training Report On Python Programming

The training report details a two-week program on Python programming undertaken by Saksham Katyal as part of his Bachelor of Technology degree. It covers the history, advantages, basic commands, functions, conditionals, and loops in Python, emphasizing its applications in various fields such as AI and IoT. The report acknowledges the support of instructors and highlights the importance of Python's readability and versatility in programming.

Uploaded by

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

Training Report On Python Programming

The training report details a two-week program on Python programming undertaken by Saksham Katyal as part of his Bachelor of Technology degree. It covers the history, advantages, basic commands, functions, conditionals, and loops in Python, emphasizing its applications in various fields such as AI and IoT. The report acknowledges the support of instructors and highlights the importance of Python's readability and versatility in programming.

Uploaded by

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

TRAINING REPORT ON PYTHON

PROGRAMMING
A Report submitted in partial fulfilment of the requirement for
the award of degree of

Bachelor of Technology
In
Electronics and Communication Engineering

Submitted by

SAKSHAM KATYAL (03896302820)

MAHARAJA SURAJMAL INSTITUTE OF TECHNOLOGY

C-4, Janakpuri, New Delhi-58

Affiliated to Guru Gobind Singh Indraprastha University, Delhi

May 2023
CERTIFICATE
ACKNOWLEDGEMENT
A training about any technology owes its success from commencement to completion
to the people attached with the person going through the training at various stages. It
is the responsibility of that person to give their best throughout the time given to them
so that everybody associated with them will be happy and proud to be with them.
Now I would like to give some heartly thanks to some peoples who gives me such
confidence and encourage me to get this beautiful opportunity. Firstly, Dr. Archana
Balyan (HOD, Department of Electronics & Communication Engineering, Maharaja
Surajmal Institute of Technology, New Delhi) for allowing me to undergo the winter
training of 2 weeks related to Python Programming by Codebasics.

Now I would like to thank the instructor of the training Dhaval Patel, who has given
very much contents and information to all which help us to do our work properly and
easily.

And in last I would love to thank other peoples those are associated with the training
for making my doubts and issues clear and for their lovely support to make this
training valuable and fruitful for me.
Contents
Abstract
In this training, I get to know some more information related to Python Programming
like where we can use it other than the usual ones. Python can be used in many areas
like AI, IoT, GUI(Graphical User Interface), etc. Other than these common areas it
can be used for making a general library of any content we want to store in it like if
we want to make any food item again and again so we can store its ingredient with its
quantity in a list which can be accessible later when we want it. Basically, in this
training I get to know these kind of some areas where we can use python and other
than this, the thing that I get to know through this training is, some advanced ideas
about Python language which are not generally taught in the basic courses of Python.
CHAPTER 1: Introduction

1.1 History of Python Programming


Python is an interpreted high level general-purpose programming language which was
firstly appeared as Python 0.9.0 on 20th February, 1991 by Guido van Rossum at
Centrum Wiskunde & Informatica(CWI) in Netherlands who was an ex-employee of
Google and worked 7 years there and in the late 1980s, he began working on Python
as a successor to the ABC programming language which was inspired by SETL. Then
Python 2.0 was released in 2000 and introduced new features such as list
comprehensions and a garbage collection system using reference counting. Python 3.0
was released in 2008 and was a major revision of the language that is not completely
backward-compatible. Basically, it was named after the cult comedy show Monty
Python’s Flying Circus but not after the snake. Its design philosophy emphasizes code
readability with its use of significant indentation. Its language constructs as well as its
object-oriented approach aim to help programmers write clear, logical code for small
and large-scale projects. Python 2 was discontinued with version 2.7.18 in 2020.
Different IDEs(Integrated Development Environment) are used to operate it easy in a
system such IntelliJ, Visual Studio Code, Anaconda, etc. Basically a IDE is an tool on
which the python programs are run. It is generally used in wide range of areas like
making projects related to technology, making robots, machines,etc.

1.2: It’s advantages over others


Python have many advantages over other programming languages which makes it
more easier and popular programming language, some of these advantages are given
below with their illustration:

1. The syntax of Python is much more easier than other languages and we usually
feels similar to using a human language as it is easy to express what we want to do
with syntax.

2. It has wide range of application as compare to other languages which makes it more
useful language.
CHAPTER 2: Basic ideas about python
programming
At a basic level, a computer program is a recipe of instructions that tells our computer
what to do and a programming language is like a ingredient to that recipe. When we
write a program, we create a step-by-step recipe of what needs to be done to complete
a task and when our computer executes the program it reads, what we wrote and
follows our instructions to the letter. In human languages, syntax means the rules we
follow to create any statement simply we called it as Grammar and semantics means
the actual meaning of that statement similarly, in programming world the meanings of
these two words are same but the way of presentation is different. Now when we talk
of Scripts, the first thing that comes to our mind literature or bunch of statements
which are written in short, simple and understandable languages using examples or
facts happened in the past and if we talk about its implementation in programming
world so it is one of the important feature appeared in it. Python is a Specific
Scripting Programming Language which has a very easy syntax which is similar to
human language which makes it different from other programming languages. This is
the reason for which most of the peoples preferred this programming language to
implement their works related to technological projects. Now in this section we are
going to enter into the basics of Python Programming like how we can write a

program, instructions, variables, etc.

2.1: Basic commands in Python

Commands are the instruction statements that are written in any program which helps
our computer to know about the task we want the computer do for us. For example, if
we want to print something so we use “print” function. Now when we are writing any
programs we should know about the syntax of commands we give to the computer to
do a specific task and that is the most important thing to remember because if we
don’t follow the syntax then our program will not work properly as we want, it started
to give errors and we have to resolve as many times it comes. Now we will talk about
some basic commands that are using in Python. In Programming World, Interpreter is
the program that reads and executes code we write.
• Print: Print is one of the basic command we give to our computer to print anything
in output according to our need. Its syntax is given below:

print(“Message to be print”)

When we write this command we get an output which prints the message we write
inside the double quotes. For example, if we want to print “Hello World” so we give a
command

print(“Hello World”)

and then our computer print the message “Hello World” in the output.

• Input: Input is the command which is used to get input from the user. Its syntax is
given below:

input(“Enter what to do you want”)

When we write this command we get an output in which the computer ask us for the
input according to preference that we have to give along with the Input command as
like integer, float, char, etc. For example, we have to input an integer then we write it
as

int(input(“Enter the value:”))

and this command help us to give input the computer.

These two commands are most important basic commands that are used in Python
Programming and these are widely used in every program because every program
needs some input and output.

2.2: More about commands in Python

We can write different instructions using “print” like mathematical expression,


characters, etc. Let us see some examples which are given below:

• print(4+5) – It will give an output as 9.

• print(4*5) – It will give an output as 20.


• print(12/2) – It will give an output as 6.0.

We also have some other mathematical operations like a**b which means a to the
power b(ab), a//b which gives the integer part of the division of the two
numbers(Quotient), a%b which gives the remainder left in the division, etc.

We can also use many operations together like print(((2050/5)-32)/9) and it will give
an output as 42.0 and these operations are done according to their priorities(or
operations from left to right).

Now have some other instructions are used sometimes to get different inputs and
output formats like image input, text file, etc.

img = imread(“Image_name.ext”) This is an example of image

imshow(img) as input.

Now can use text file also as our task like reading text files, writing in text files and
for all this we have different formats which are given below:

txt = open(“filename.txt”, mode)

This is the basic syntax to open a text file in which we can specify the mode in which
we want this file to open either it be in reading mode or writing mode. For mode we
have some words to use like ‘r’ as reading mode, ‘w’ as writing mode, ‘a’ as
appending mode, ‘b’ as binary mode, etc.

print(txt.read()) – This command is used to read the file we open.

print(txt.readline()) – This command is used to read a single line in the text file.

print(txt.write()) – This command is used to write in the text file.

seek(0) – This is used to move to the beginning read/write location of the file.

2.3: Different useful parts of a program

Keywords are the words which are specified by the computer to do any specific task.
There are some keywords given below:

false class finally is return none continue


for lambda try true def from no local

while and del global not with as

elif if or yield assert else import

Pass break except in raise

These can be used to do any specific work in our program whenever we want.

Datatypes are basically the types of working contents we want to deal with for
examples integers, strings, float, etc.

In this, we can use “type” function to get the type of the content.

print(type(a)) - <class ‘str’> is the output which shows that the content ‘a’ is a string.

Variables are names that we give to certain values in our programs. Those values can
be of any datatype; numbers, strings or even the results of operations. The process of
storing a value inside a variable is known as “assignment”.

A expression is a combination of numbers, symbols or other variables that produce a


result when evaluated.

There are some rules to give names to the variables in our program which are given
below:

(1.) We shouldn’t use variables name as any of the keywords or functions that Python
reserves for its own like print, input, etc.

(2.) Variable names can’t have any spaces and they must start with either a letter or an
underscore, for example, I_am_a_variable is the valid variable name, 1_is_a_number
is invalid, Apples_&_Oranges is invalid.

(3.) They can only be made up of letters, numbers and underscores.

(4.) Precision is important when programming, Python variables are case-sensitive, so


capitalization matters. Lowercase name, uppercase name and all caps name are all
valid and different variable names and that rule on variable is invariable.
The computer is busy automatically converting an integer into a float. This lets
Python then add together the values to return results that is also a float. We call this
process as “Implicit Conversion”.

We can use “+” operator to add together strings or numbers.

We can convert integer into string using “str” function similarly if we want to convert
into integers then we use “int” function.

Explicit Conversion is where we manually convert from one datatype to another by


calling the relevant function for the datatype we wantr to convert to.

There are some special characters which are used to some special tasks these are
known as “Escape Sequences”, some of these are given below:

\| - Backslash \’ – Single Quote \” – Double Quote

\a – Bell \b – Backspace \f – formfeed \n – newline

\r – carriage \t – tab \v – vertical tab

There are some other points which are to be mentioned other than points discussed
earlier:

• We use “continue” statement in the program for a purpose, that is, if we want to skip
a particular data placed sequencially and to print other datas then we use it as it skip
the particular data that we don’t want to print and print all other datas.

• We also use “break” statement in the program, it is different from continue as it


comes out of the loop when condition match and only prints the data placed before the
condition data reaches.

• “pass” statement is used to make the code syntactically correct.

• We use “augmented assignment” which the combination of binary operators and


assignment statement in a single line, i.e., for example, a += 1

Global Variables: These are the variables which are defined in the main part of the
program.
Local Variables: These are the variables defined within a function or only exist exist

inside a function.

2.4: Functions

Now we are going to talk about functions which are one of the most important section
in a programming. Basically, a function is used to perform any task separately and we
call it everytime we need to do that task multiple times. Function is used reduce the
complexity in the program as it reduces the chance of error when we are writing any
program, it makes easy for us to get output for multiple call. For example, if we want
to get data of many students separately so we make a function for a general student
and call it for every student. Now firstly we should know about the syntax of function
before we use it.

The syntax of function is given below:

>>> def function_name(arguments):

… // body of the code

In this, arguments are the variables which we want to pass to the function so that we
don’t have to define it again and again.

In function, we can also return values using “return” keyword. Sometimes, the output
is “None” when we return something because None is a special datatype in Python
which is used to indicate that things are empty or that they returned nothing.

2.5: Conditionals

Conditionals are the statements which are used to compare things or get an output
according to some conditions if it satisfies one condition then the output will be
according to that condition body. In this we have different types of statements like
arithmetic & logical operators, If-statement, Else-Statement, Else-If (Elif) Statement.

(1.) Arithmetic & Logical Operators: In this, we have some operators which are
used to compare things so that we get our desired output.
There are some examples which are shown below:

> - Greater than < - less than == - equal

>= - Greater than or equal <= - less than or equal != - Not Equal

not(!) – NOT operation and(&&) – AND operation or(||) – OR operation

(2.) If-Statement: In this, we have a condition if it satisfies the body inside it, will
execute otherwise, the statements outside it, will execute.

For example,

if(x>y): Now if x is greater than y then x

print(x) will be printed otherwise 0 is printed.

print(0)

(3.) Else-Statement: In this, we have two conditions one is for if statement and other
is for else statement. If the statement in “If” satisfies then the body inside it will
execute otherwise the body inside “else” will execute.

For example,

if(x>y): Now if x is greater than y then x will be

print(x) printed otherwise y will be printed.

else:

print(y)

(4.) Else-If(Elif) Statement: In this, we have some more conditions inside else
conditions that’s why it is called elif statement.

For example,

if(x>y): Now if x is greater than y then x will be

print(x) printed otherwise if x equals to y then 0

elif(x==y): will be printed and if both the conditions

print(0) failed then y will be printed.

else:

print(y)
2.6: Loops

Loops are repetition of any work again and again until the limit specified reaches.
Recursion is also a type of loop.

We have three types of loop to study

i. While Loop

ii. For Loop

iii. Recursion

(i.) While Loop: While Loops instruct our computer to continuously execute our code
based on the value of a condition. This works in a similar way to branching if
statements. The difference here is that the body of the block can be executed multiple
times instead of just once. The syntax is given below:

while(condition):

//Body of the block

In python, we use the “break” keyword which we can used to stop the running of the
current loop.

(ii.) For Loop: A “For” loop iterates over a sequence of values. The syntax is given
below:

for(condition):

//Body of the block

In this we can use “range” function which can be used to give a range of numbers in
between the arguments passed to it.

Range function can be written in many ways which are given below:

i. range(i) – This will be all integer numbers till the number “i” and its initial point
would be 0.

ii. range(m,n) – This will give all integer numbers between m and n.
iii. range(m,n,i) – This will give all in integer numbers between m and with the step I

2.7: String, Lists, Dictionaries

Now other than integer datatypes we have some other datatypes also and these are
strings, lists and dictionaries. Now in this section, we are going to study about these
datatypes.

(1.) Strings: A String is a datatype in Python that’s used to represent a piece of text.
It’s written between quotes, either double or single, it’s all about our choice. In this,
we have some processes which we apply on strings such as concatenation, indexing,
slicing, etc. The String is defined as given below:

String_name = “message”

We can also get character at index i in the given string by writing String_name[i],
which will give the character at ith position from starting index which is generally 0.
Now if i is negative then the ith character from backwards will be printed.

Now, a “slice” is the portion of a string that can contain more than one character, also
sometimes called a “substring”.

Color = “orange”

Color[1:4] It will print “ran”

We can also create new strings using slicing and “+” operator. There is a negative
slicing also there in which we a negative indexing then it will be count from backward
to the position that we write in negative number.

(2.) Lists: A list is a collection of items arranged in one place. It can be defined as:

List_name = [“ ”,…]

We can also get items of the list same as in strings. There also some functions which
are used in modification of lists, these are:

Append(), insert(), remove(), pop(), enumerate(), sort(), extend(), etc.


Now we an immutable datatype which is “tuple”, it is a mathematical name for an
ordered set of data and these are written in parenthesis[()] instead of square brackets.
We can also use nested data structures, which means list inside a list can be possible.

We can also use content of one list into another list by using “import” keyword. It is
generally used for adding external contents to our program which are not in-built.

Python provides a technique called “list comprehension” that lets us create a list in
just one line.

For example,

multiples = [] It will be the output as given

for x in range(1,11): below:

multiples.append(x*7) [7,14,21,28,35,42,49,56,63,70]

print(multiples)

(3.) Dictionaries: The data inside dictionaries take the form of keys and values. It
means the data in dictionaries are placed with the own keys.

It can be defined as given below:

X={}

Dictionaries are mutable which means we can change its data. In this, we can also use
some of the functions and keywords which are useful, these are del, items(), keys(),
values(), len(), get(), update(), clear(), setdefault(), list(), iter(), copy(), fromkeys(),
etc.

Set is an unordered collection with no duplicate entries. Python sets work the same
way as they do in set theory. [Set()]. The keys of a dictionary are very similar to a set.
Sets have no ordering but the dictionary keys are ordered. There are some functions,
these are add(), discard(), remove(), union()[dict1 | dict2], update(), intersection()
[dict1 & dict2], difference()[dict1 – dict2], symmetric_difference()[dict1 ^ dict2],

issubset(), issuperset(), etc.

.
CHAPTER 3: Object Oriented Programming
Now in this section, we are going to talk about Object-Oriented Programming (OOP)
in Python, which is one of the important topic in python. Generally, when we talk
about OOP the first thing comes to our mind is class.

Q. What is Object-Oriented Programming?

- To make the concept of anything easier for computers to understand the concepts,
Python uses a programming pattern called “Object-Oriented Programming”, which
models concepts using classes and objects. This is a flexible, powerful paradigm
where classes represent and define concepts, while objects are instances of classes.
The attributes are the characteristics associated to a type and the methods are the
functions associated to a type.

Classes and Objects in Python

We can get our computer to list all the attributes and methods in a class. To do that we
just use the “dir” function. This gets the interpreter to print to the screen a list of all
the attributes and methods.

>>> dir(“ ”)

_len_method – len function

_ge_method – To compare if one string is greater than or equal to another.

>>> help(“ ”)

When we use the “help” function on any variable or value, we’re showing all the
documentation for the corresponding class. When we’re done looking at
documentation, we can just type q to quit.

Defininig a new class:

>>> class name: “pass” is a keyword used to show that the

… pass class is empty.


“pass” keyword can also be used as placeholder in any empty python block.

Dot Notation is a syntax used to access the attributes.

Now there is a term called as “constructors” which are generally special types of
method which are defined inside a class for a special purpose. For example,

>>> class Apple:

… def _init_(self,color,flavor): Here constructor is defined.

… self.color = color

… self.flavor = flavor

Then there is one more thing term which is important in class is “inheritance” which
is used to for code reuse. We can use a class into another class.

The principle of inheritance let’s a programmer build relationships between concepts


and group them together. In particular, this allows u to reduce code duplication by
generalizing our code. This is one of the widest used concept in OOPs because
relation between two classes makes it easier for everyone to make a complex
program.

We can define a base class that objects are based on, things that are common for
classes that derive from the base class. Then we can allow a class to define the unique
characteristics of itself. Base class is also referred as “superclass”.

SO a class can have more than one superclass and this method is known as “multiple
inheritance”.

Polymorphism: It basically means that objects can be more than one thing at the
same time.

Encapsulation: Objects contain the data and the methods that operate on that data
and don’t expose the actual implementation to the outside world. It generally means to
start our class name as Capital letter.

Raw String: It gives the same line without functioning the escape sequences. For
example,
raw_string = r“how\nwell\tyou” It will print :

print(raw_string) how\nwell\tyou

You might also like