Training Report On Python Programming
Training Report On Python Programming
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
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. 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
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:
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
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.
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.
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:
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.readline()) – This command is used to read a single line in the text file.
seek(0) – This is used to move to the beginning read/write location of the file.
Keywords are the words which are specified by the computer to do any specific task.
There are some keywords given below:
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”.
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.
We can convert integer into string using “str” function similarly if we want to convert
into integers then we use “int” function.
There are some special characters which are used to some special tasks these are
known as “Escape Sequences”, some of these are given below:
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.
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.
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 or equal <= - less than or equal != - Not Equal
(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,
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,
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,
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.
i. While 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):
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):
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
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”
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:
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.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.
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],
.
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.
- 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.
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(“ ”)
>>> 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.
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,
… 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.
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