Python Report
Python Report
AN
Bachelor of Technology
in
INFORMATION TECHNOLOGY
by
2021-
2022
Certificate
The report submitted by Rohit Dinkar Gaikwad (PRN No. 2030331246036) is approved for the
partial fulfillment of the requirement for the award of the degree of Bachelor of Technology in
Information Technology Engineering.
Acknowledgement
This work is just not an individual contribution till its completion. I take this opportunity to express a
deep gratitude in learning online course for providing excellent guidance encouragement and
inspiration throughout the Training work. This work have been a successful one.
I wish to express my sincere thanks to all the department faculties and staff members for their support.
I would also like to thank my all classmates for their valuable guidance and helpful discussion.
INDEX
1 Introduction 0
2 History of Python 2
3 About Python 4
4 Installing Python 6
5 Python comments 7
6 Python variable 8
7 Python keywords 9
9 Python operators 11
10 Python lists 12
11 Python tuples 13
12 Python dictionary 14
13 Conditional statements 15
14 Python functions 18
16 Python iterators 21
17 Modules 22
CHAPTER 01
INTRODUCTION
Scripting Language
A scripting or script language is a programming language that supports scripts,
programs written for a special run-time environment that automate the
execution of tasks that could alternatively be executed one-by-one by a human
operator. Scripting languages are often interpreted (rather than compiled).
Primitives are usually the elementary tasks or API calls, and the language allows
them to be combined into more complex programs. Environments that can be
automated through scripting include software applications, web pages within a
web browser, the shells of operating systems (OS), embedded systems, as well
as numerous games.
A scripting language can be viewed as a domain-specific language for a particular
environment; in the case of scripting an application, this is also known as an
extension language. Scripting languages are also sometimes referred to as very
high-level programming languages, as they operate at a high level of abstraction,
or as control languages.
0
‘A Report on Python for beginners 2021’
1
‘A Report on Python for beginners 2021’
CHAPTER 02
History
Python was conceived in the late 1980s, and its implementation was started in
December 1989 by Guido van Rossum at CWI in the Netherlands as a successor
to the ABC language (itself inspired by SETL) capable of exception handling and
interfacing with the Amoeba operating system. Van Rossum is Python's principal
author, and his continuing central role in deciding the direction of Python is
reflected in the title given to him by the Python community, benevolent dictator
for life (BDFL)
Van Rossum
CHAPTER 03
2
‘A Report on Python for beginners 2021’
• Computer programming has an integral role in our world. You would not
be reading this article without it. In fact, without computer programming
you would not be able to use your cell phone, computer or smart TV.
Learning the fundamentals of programming can set you apart from your
counterparts, giving you a competitive edge in this technology-driven
world. Earning a computer programming degree can help you innovate and
create solutions for a global society.
What Is Programming?
What Is a Program?
CHAPTER 04
About Python
What is Python?
‘Department of Computer Engineering ‘
Dr. Babasaheb Ambedkar Technological University, Lonere.
3
‘A Report on Python for beginners 2021’
Python is a popular programming language. It was created by Guido van Rossum, and released
in 1991.
It is used for:
• Python can connect to database systems. It can also read and modify files.
• Python can be used to handle big data and perform complex mathematics.
Why Python?
• Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
• Python has syntax that allows developers to write programs with fewer lines than some
other programming languages.
• Python runs on an interpreter system, meaning that code can be executed as soon as it
is written. This means that prototyping can be very quick.
Good to know
• The most recent major version of Python is Python 3, which we shall be using in this
tutorial. However, Python 2, although not being updated with anything other than
security updates, is still quite popular.
• In this tutorial Python will be written in a text editor. It is possible to write Python in an
Integrated Development Environment, such as Thonny, Pycharm, Netbeans or
‘Department of Computer Engineering ‘
Dr. Babasaheb Ambedkar Technological University, Lonere.
4
‘A Report on Python for beginners 2021’
Eclipse which are particularly useful when managing larger collections of Python files.
• Python was designed for readability, and has some similarities to the English language
with influence from mathematics.
• Python relies on indentation, using whitespace, to define scope; such as the scope of
loops, functions and classes. Other programming languages often use curly-brackets for
this purpose.
CHAPTER 05
Installing Python
• To check if you have python installed on a Windows PC, search in the start bar for
Python or run the following on the Command Line (cmd.exe):
C:\Users\Your Name>python –version
• To check if you have python installed on a Linux or Mac, then on linux open the command
line or on Mac open the Terminal and type: Python –version
5
‘A Report on Python for beginners 2021’
If you find that you do not have python installed on your computer, then you can download it
for free from the following website:
https://www.python.org/
CHAPTER 06
Python Comments
Creating a Comment
• Comments starts with a # , and Python will ignore them:
1. Example
6
‘A Report on Python for beginners 2021’
#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:
2. Example
• A comment does not have to be text that explains the code, it can also be used to prevent
Python from executing code:
3. Example
#print(“Hello, World!”)
Print(“Cheers, Mate!”)
CHAPTER 07
Python Variables
VARIABLES
• Variables are the Container for storing data values.
• A variable is a name given to a memory location.
Creating Variables
• Variables do not need to be declared with any particular type, and can even change
type after they have been set.
Casting
7
‘A Report on Python for beginners 2021’
If you want to specify the data type of a variable, this can be done with casting.
• Example
Y = int(3) # y will be 3
Variable name
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
CHAPTER 08
Python keywords
• Value Keywords:
True, False, None
• Operator Keywords:
and, or, not, in, is
• Iteration Keywords:
for, while, break, continue, else
• Structure Keywords:
‘Department of Computer Engineering ‘
Dr. Babasaheb Ambedkar Technological University, Lonere.
8
‘A Report on Python for beginners 2021’
• Returning Keywords:
return, yield
• Import Keywords:
import, from, as
• Exception-Handling Keywords:
try, except, raise, finally, else, assert
CHAPTER 09
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
Text Type: str
dict
Mapping Type:
9
‘A Report on Python for beginners 2021’
CHAPTER 10
Python operators
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
+, -, *, /, % , //, **
10
‘A Report on Python for beginners 2021’
Identity operators are used to compare the objects, not if they are equal, but if they are
actually the same object, with the same memory location:
Is, is not
Python Membership Operators
Membership operators are used to test if a sequence is presented in an object:
In , not in
List
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python used to store collections of data,
the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
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.
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
List Length
11
‘A Report on Python for beginners 2021’
To determine how many items a list has, use the len() function
Type()
From Python’s perspective, lists are defined as objects with the data type
‘list’
12
‘A Report on Python for beginners 2021’
CHAPTER
12
Python Tuples
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:
Tuple Length
• To determine how many items a tuple has, use the len() function:
• To create a tuple with only one item, you have to add a comma after the item,
otherwise Python will not recognize it as a tuple.
13
‘A Report on Python for beginners 2021’
CHAPTER
13
Python Dictionary
Dictionary
Dictionaries are used to store data values in key:value pairs.
Dictionaries are written with curly brackets, and have keys and values: •
Dictionary Items
Dictionary items are ordered, changeable, and does not allow duplicates.
Dictionary items are presented in key:value pairs, and can be referred to by using the
key name.
• Changeable
Dictionaries are changeable, meaning that we can change, add or
remove items after the dictionary has been created.
• Dictionary Length
To determine how many items a dictionary has, use the len() function:
14
‘A Report on Python for beginners 2021’
CHAPTER
14
Conditional statements
• If else
• For loop
• While loop
Python Conditions and If statements
These conditions can be used in several ways, most commonly in “if statements” and loops.
Example
If statement:
a = 36 b =
200
If b > a:
Print(“b is greater than a”) Indentation
Python relies on indentation (whitespace at the beginning of a line) to define scope in the
code. Other programming languages often use curly-brackets for this purpose.
Elif
The elif keyword is pythons way of saying "if the previous conditions were not true, then try
this condition".
Else
15
‘A Report on Python for beginners 2021’
CHAPTER
The else keyword catches anything which isn't caught by the preceding conditions.
16
‘A Report on Python for beginners 2021’
Nested If
You can have if statements inside if statements, this is called nested if statements.
With the while loop we can execute a set of statements as long as a condition is
true.
Example
i = 1 while
i < 6:
print(i) i
+= 1
The while loop requires relevant variables to be ready, in this example we need to
define an indexing variable, i, which we set to 1.
With the break statement we can stop the loop even if the while condition is true:
Example
i = 1 while
i < 6:
print(i) if
i == 3:
break i
+= 1
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set,
or a string).
17
‘A Report on Python for beginners 2021’
This is less like the for keyword in other programming languages, and works more
like an iterator method as found in other object-orientated programming
languages.
With the for loop we can execute a set of statements, once for each item in a list,
tuple, set etc.
Example
Example
Using the range() function:
For x in range(6):
Print(x)
CHAPTER 15
Python functions
18
‘A Report on Python for beginners 2021’
a function.
Creating a Function
Example
def my_function():
print("Hello from a function")
Calling a Function
Example
def my_function():
print("Hello from a function")
my_function()
Arguments
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.
The following example has a function with one argument (fname). When the
function is called, we pass along a first name, which is used inside the function
to print the full name:
19
‘A Report on Python for beginners 2021’
Example
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
Parameters or Arguments?
The terms parameter and argument can be used for the same thing: information
that are passed into a function.
Number of Arguments
By default, a function must be called with the correct number of arguments.
Meaning that if your function expects 2 arguments, you have to call the function
with 2 arguments, not more, and not less.
CHAPTER 16
20
‘A Report on Python for beginners 2021’
Create a Class
To create a class, use the keyword class
The examples above are classes and objects in their simplest form, and are not
really useful in real life applications.
All classes have a function called __init__(), which is always executed when the
class is being initiated.
Object Methods
Objects can also contain methods. Methods in objects are functions that belong to
the object.
The self parameter is a reference to the current instance of the class, and is used to
access variables that belongs to the class.
It does not have to be named self , you can call it whatever you like, but it has to
be the first parameter of any function in the class:
21
‘A Report on Python for beginners 2021’
• An iterator is an object that can be iterated upon, meaning that you can
traverse through all the values.
Iterator vs Iterable
Lists, tuples, dictionaries, and sets are all iterable objects. They are iterable
containers which you can get an iterator from.
All these objects have a iter() method which is used to get an iterator:
Create an Iterator
all classes have a function called __init__(), which allows you to do some
initializing when the object is being created.
The __iter__() method acts similar, you can do operations (initializing etc.), but
must always return the iterator object itself.
The __next__() method also allows you to do operations, and must return the next
item in the sequence.
StopIteration
The example above would continue forever if you had enough next() statements,
or if it was used in a for loop.
CHAPTER 18
Introduction to modules What
is a Module?
22
‘A Report on Python for beginners 2021’
Create a Module
To create a module just save the code you want in a file with the file extension
.py:
Use a Module
Now we can use the module we just created, by using the import statement:
Naming a Module
You can name the module file whatever you like, but it must have the file
extension .py
Re-naming a Module
You can create an alias when you import a module, by using the as keyword:
Built-in Modules
There are several built-in modules in Python, which you can import whenever you
like.
There is a built-in function to list all the function names (or variable names) in a
module.
You can choose to import only parts from a module, by using the
from keyword.
Conclusion
23
‘A Report on Python for beginners 2021’
References
24
‘A Report on Python for beginners 2021’
25