1. Dr. A. B. Shinde
Assistant Professor,
Electronics and Computer Science,
P V P Institute of Technology, Sangli
Introduction to Python
2. Dr. A. B. Shinde
Contents…
• Introduction:
• History of Python,
• Need of Python,
• Features of Python,
• Comparison with C and Java,
• Python Building Blocks:
– Keywords, Identifiers,
– Variables, Comments, Docstring,
– Indentation, Input-Output.
• Python Installation:
• Python Installation with 3.x version, Working with various IDE:
• Command Prompt, IDLE, Jupyter Notebook, Google Colab, Pycharm,
VS Code, Spyder.
2
4. Dr. A. B. Shinde
Python History 4
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 to emphasize code readability, and its syntax
allows programmers to express concepts in fewer lines of code.
5. Dr. A. B. Shinde
Python History 5
In the late 1980s, working on Python started.
Soon after that, Guido Van Rossum began doing its application-based
work in December of 1989 at Centrum Wiskunde & Informatica (CWI)
which is situated in the Netherlands.
It was started as a hobby project because he was looking for an
interesting project to keep him occupied during Christmas.
7. Dr. A. B. Shinde
What is Python? 7
Python is a high-level programming language celebrated for its
simplicity, readability, and versatility.
Python supports multiple programming paradigms and boosts an
extensive standard library that simplifies coding tasks.
Its large ecosystem of third-party libraries and frameworks further
enhances its capabilities, making it a top choice for web development,
scientific computing, data analysis, artificial intelligence, machine
learning, and automation.
Python’s clear syntax and strong community support contribute to its
popularity among beginners and experienced developers.
8. Dr. A. B. Shinde
Why Python? 8
Data Science
• Python is the preferred programming language of most data scientists.
• With the release of NumPy and Pandas, Python rose to prominence in
the world of data.
• Python also handles statistical, tabular and matrix data and also
visualizes it with libraries like Matplotlib and Seaborn.
Easy to Learn
• Python’s resemblance to the English language makes it easy to master.
• Python’s syntax is characterized by very few rules and special cases.
• Another attractive aspect of this programming language is its efficiency
and readability.
9. Dr. A. B. Shinde
Why Python? 9
Cross-Platform and Open Source
• It’s been more than 20 years since this language has been running
cross-platform and open source.
• Be it Linux, Windows or MacOS, Python code works on every platform.
Vast Libraries
• Python is supported by PyPI which has 85,000+ python scripts and
modules accessible to the user.
• These modules provide pre-packaged functionality available to the
users in their local Python environment.
10. Dr. A. B. Shinde
Why Python? 10
Benefits of using Python
• Readability: Python’s syntax is designed to be easily readable, making
it easier to write and maintain code.
• Easy to learn and use: Python’s simple syntax makes it beginner-
friendly
• Extensive libraries and frameworks: Offers rich libraries for web
development, data science, AI, etc.
• Versatile: Supports multiple programming paradigms and applications
• Cross-platform: Works seamlessly across Windows, macOS, and
Linux
• Great for rapid prototyping: Quick syntax allows for fast idea
implementation
12. Dr. A. B. Shinde
Features of Python 12
1. Free and Open Source
• Python language is freely available at the official website.
• It is open-source, this means that source code is also available to the
public.
2. Easy to code
• Python is very easy to learn as compared to other languages like C, C#,
Javascript, Java, etc.
• It is also a developer-friendly language.
3. Easy to Read
• Python’s syntax are straightforward.
• It makes the code more readable.
13. Dr. A. B. Shinde
Features of Python 13
4. Object-Oriented Language
• Python supports object-oriented language and concepts of classes,
object encapsulation, etc.
5. GUI Programming Support
• Graphical User interfaces can be made using a module such as PyQt5,
wxPython, or Tk in Python. PyQt5 is the most popular option for
creating graphical apps with Python.
6. High-Level Language
• Python is a high-level language.
7. Large Community Support
• Questions are constantly answered by the community.
14. Dr. A. B. Shinde
Features of Python 14
8. Easy to Debug
• Excellent for mistake tracing. You will be able to quickly identify and
correct the majority of your program’s issues once you understand how
to interpret Python’s error traces.
9. Python is a Portable language
• Python language is also a portable language, we can run python code
on any platform.
• Python code written for Windows can run on other platforms such
as Linux, Unix, and Mac then we do not need to change it,
10. Python is an Integrated language
• Python is also an Integrated language because we can easily integrate
Python with other languages like C, C++, etc.
15. Dr. A. B. Shinde
Features of Python 15
11. Interpreted Language:
• Python is an Interpreted Language because Python code is executed
line by line at a time.
• There is no need to compile Python code this makes it easier to debug
our code.
12. Large Standard Library
• Python has a large standard library that provides a rich set of modules
and functions
13. Dynamically Typed Language
• Python is a dynamically-typed language. That means the type (for
example- int, double, long, etc.) for a variable is decided at run time not
in advance because of this feature we don’t need to specify the type of
variable.
16. Dr. A. B. Shinde
Features of Python 16
14. Frontend and backend development
• With a new project py script, you can run and write Python codes in
HTML with the help of some simple tags <py-script>, <py-env>, etc.
• This will help you do frontend development work in Python like
javascript.
• Backend is the strong forte of Python it’s extensively used for this work
cause of its frameworks like Django and Flask.
15. Allocating Memory Dynamically
• In Python, the variable data type does not need to be specified.
• The memory is automatically allocated to a variable at runtime when it is
given a value.
18. Dr. A. B. Shinde
Comparison of Python 18
Feature Python C C++ Java
Type Interpreted Compiled Compiled
Compiled and
Interpreted
Paradigm
Multi-paradigm (object-
oriented, procedural,
functional)
Procedural, structured
Multi-paradigm
(procedural, object-
oriented, generic)
Object-oriented,
structured
Memory
Management
Automatic Manual Manual Automatic
Syntax Simple Complex Complex Complex
Use Cases
Web development,
data analysis, machine
learning
System programming,
embedded systems,
game development
System programming,
game development,
high-performance
applications
Large-scale
applications,
enterprise software
Notable
Frameworks/
Libraries
Django, Flask Standard Library
Standard Library,
Boost
Spring, Hibernate
Community
Support
Strong Strong Strong Strong
19. Dr. A. B. Shinde
Comparison of Python 19
Python vs Java
For Example, Here is a code in Java
Same code written in Python
21. Dr. A. B. Shinde
Python Basics 21
Python Syntax
Syntax refers to the set of rules that defines how to write and organize
code so that the Python interpreter can understand and run it correctly.
These rules ensure that your code is structured, formatted, and error-
free.
22. Dr. A. B. Shinde
Python Basics 22
Python keywords
Keywords are reserved words that have special meanings and serve
specific purposes in the language syntax.
They cannot be used as identifiers (names for variables, functions,
classes, etc.).
For instance, "for", "while", "if", and "else" are keywords and cannot be
used as identifiers.
alse await else import pa
one break except in raise
rue class finally is return
nd continue for lambda try
s def from nonlocal while
ssert del global not with
sync elif if or yield
23. Dr. A. B. Shinde
Python Basics 23
• Python Identifiers
• In identifiers are unique names that are assigned to variables,
functions, classes, and other entities.
• They are used to uniquely identify the entity within the program.
• They should start with a letter (a-z, A-Z) or an underscore "_" and can
be followed by letters, numbers, or underscores.
• In the below example "first_name" is an identifier that store string value.
first_name = "Ram"
24. Dr. A. B. Shinde
Python Basics 24
Python Identifiers
• Identifier : some rules
• Identifiers can be composed of alphabets (either uppercase or
lowercase), numbers (0-9), and the underscore character (_).
• They shouldn't include any special characters or spaces.
• The starting character of an identifier must be an alphabet or an
underscore.
• Within a specific scope or namespace, each identifier should have a
distinct name to avoid conflicts.
A = 3.14
x = 3.14
Num = 3.14
Sagar = 3.14
Pi = 3.14
25. Dr. A. B. Shinde
Python Basics 25
• Python Variables
• Variables in Python are essentially named references pointing to objects
in memory.
• You don't need to declare a variable's type explicitly in Python. Based on
the value assigned, Python will dynamically determine the type.
• In the below example, variable 'a' is initialize with integer value and
variable 'b' with a string. Because of dynamic-types behavior, data type
will be decide during runtime.
26. Dr. A. B. Shinde
Python Basics 26
• Comments in Python
• Comments are used to explain, clarify, or give context about specific
parts of the code.
• The purpose of comments is to explain the working of a code, they have
no impact on the execution or outcome of a program.
• Python Single Line Comment
• Single line comments are preceded by the "#" symbol.
• Everything after this symbol on the same line is considered a comment.
27. Dr. A. B. Shinde
Python Basics 27
Comments in Python
• Python Multi-line Comment
• Python doesn't have a specific syntax for multi-line comments.
• However, programmers often use multiple single-line comments, one
after the other, or sometimes triple quotes (either ''' or """), even though
they're technically string literals.
• Below is the example of multiline comment.
28. Dr. A. B. Shinde
Python Basics 28
• Multiple Line Statements
• Writing a long statement in a code is not feasible or readable.
• Breaking a long line of code into multiple lines makes is more readable.
• Using Backslashes ()
• In Python, you can break a statement into multiple lines using the
backslash ().
29. Dr. A. B. Shinde
Python Basics 29
• Continuation of Statements in Python
• Statements are typically written on a single line.
• There are scenarios where writing a statement on multiple lines can
improve readability or is required due to the length of the statement.
• Implicit Continuation
• Python implicitly supports line continuation within parentheses ( ),
square brackets [ ], and curly braces { }.
30. Dr. A. B. Shinde
Python Basics 30
• Continuation of Statements in Python
• Statements are typically written on a single line.
• There are scenarios where writing a statement on multiple lines can
improve readability or is required due to the length of the statement.
• Explicit Continuation
• You can use backslash '' to indicate that a statement should continue
on the next line.
31. Dr. A. B. Shinde
Python Basics 31
• Input from User in Python
• The input( ) function in Python is used to take user input from the
console.
• The program execution halts until the user provides input and presses
"Enter". The entered data is then returned as a string.
• Example: The user will see the message "Please enter your name: ".
• After entering their name and pressing "Enter", they'll receive a greeting
with the name they provided.
32. Dr. A. B. Shinde
Python Basics 32
• Input from User in Python
• Take Multiple Input in Python
• We are taking multiple inputs from the user in a single line, splitting the
values entered by the user into separate variables for each value using
the split( ) method.
• Then, it prints the values with corresponding labels, either two or three,
based on the number of inputs provided by the user
33. Dr. A. B. Shinde
Python Basics 33
• Input from User in Python
• Take Conditional Input from user
• The input is converted to an integer using the int() function.
• Then, the program uses conditional statements to check the age range
and prints a message based on whether the user is a minor, an adult, or
a senior citizen.
34. Dr. A. B. Shinde
Python Basics 34
Output in Python:
• print( )
• print() function allows us to display text, variables and expressions on
the console.
• In this example, “SY ECS, PVPIT” is a string literal enclosed within
double quotes.
35. Dr. A. B. Shinde
Python Basics 35
Output in Python:
• Printing Variables
• We can use the print( ) function to print single and multiple variables.
• We can print multiple variables by separating them with commas.
• Example:
36. Dr. A. B. Shinde
Python Basics 36
Output in Python:
Output Formatting
Example: Using Format( )
37. Dr. A. B. Shinde
Python Basics 37
Output in Python:
Output Formatting
Example: Using sep and end parameter
38. Dr. A. B. Shinde
Python Basics 38
Output in Python:
Output Formatting
Example: Using f-string