Python Basics
Introduction to Python Programming
Learning Objectives
By the end of this lesson, you will be able to:
Learn about the history of Python
Explore advantages of using Python
Install Python and identify its IDE
Explore how to use Jupyter notebook
Execute a Python program
Implement Python identifiers, indentation, and comments
Business Scenario
ABC Inc. is planning to explore and work on artificial intelligence projects. The
organization is currently struggling to choose the right programming language for
their projects and to keep functionality, scalability, and efficiency as priority
factors to be maintained along with a better developer experience.
Python is chosen as the programming language for all prospective projects
because it is simple, secure, scalable, and rich in built-in libraries.
In this lesson, we will explore the following:
• What is Python and its advantages
• Installation of Python
• Python identifiers, indentations, and comments
• Execution of Python programs
Introduction to Python
Discussion
Python
• Is Python a programming language or a scripting language?
• What is Python, and why was it introduced when there were other
languages?
• What are its benefits over other languages?
Python: History
Python is a widely-used programming language that was conceived in the late 1980s.
Python was invented by It is named after the It is now maintained It is derived from
Guido Van Rossum (CWI, BBC comedy series by the Python ABC, Modula-3,
Amsterdam). “Monty Python's Flying Software Lisp, and “C “
Circus”. Foundation (PSF). languages.
Python: Definition
• Python is a high-level, interpreter based, object-oriented
programming language with dynamic semantics.
• It is a simple, general-purpose programming language and
can be used for various applications, such as data science
and automation.
• Python's simple and easy-to-learn syntax emphasizes
readability and reduces the cost of program maintenance.
• Python supports modules and packages, which encourages
program modularity and code reuse.
• Python is a free and open-source language.
Python: Advantages
The advantages of Python are:
Flexible Easy to learn and use
It aids in the cross-platform It uses a minimal amount of
compatibility and scripting of code to complete tasks.
web pages and applications.
Readability and maintenance Robust standard library
Python places a strong emphasis It allows selecting a module
on readable code and permits from a large selection based on
the use of English keywords in the requirement.
place of punctuation.
Python: Technical Strengths
Python has the following strengths which make it user-friendly:
Object-oriented Supports advanced notions, such as polymorphism, operator overloading, and
programming multiple inheritances
Free and • Allows modification, and redistribution of the source code
open-source • Provides free license
• Can be implemented on every major platform
Portable
• Can be used with Unix, Linux, MS-DOS, MS Windows, Macintosh, and IBM
• Provides dynamic typing and automatic memory management
Powerful
• Provides built-in objects and tools that consist of library and third-party utilities
• Can be easily "glued" to components written in other languages
Compatible
• Allows adding functionality to existing systems
Python: Industrial Use Cases
Python is widely used in the following platforms:
YouTube
Python is primarily used to construct the well-known YouTube video-sharing
system.
Google
Python is being extensively used in Google’s web search system.
DropBox
The server and client’s software of DropBox is primarily coded in Python.
Python: Industrial Use Cases
Python is widely used in the following platforms:
BitTorrent
The peer-to-peer file-sharing system started off as a Python program.
NASA
Python is being used at NASA for specific programming tasks.
Netflix
Python is used through the "full content life cycle,” at Netflix.
Python
• Is Python a programming language or a scripting language?
Answer: Python is a programming language.
• What is Python, and why was it introduced when there were other
languages?
Answer: Python is a widely-used programming language that was conceived
in the late 1980s. Python is a portable, free, open-source, powerful, and
compatible language, which makes it better than other programming
languages.
• What are its benefits over other languages?
Answer: Python is flexible, easy to use, has better readability and
maintenance, and has a robust standard library.
Python Installation
Discussion
Python
You are a data scientist and are supposed to teach the trainees to install
Python in everyone's system. However, a few of them are facing issues with
the installation. You need to guide the team to install Python using both
methods.
The trainees must install Python in any one of the two methods and share
the output after installation.
Python: Installation
There are two ways to install Python:
1. Install Python using the URL:
Step 1.1: The latest or required version of Python for a specific platform can be
installed from the official Python website: https://www.python.org/
Python: Installation
There are two ways to install Python:
Step 1.2: Click on the Downloads to download Python:
Python: Installation
There are two ways to install Python:
2. Install Python from the anaconda file distribution system
Step 2.1: Click on the link: https://www.anaconda.com/products/distribution
Specific platform
Recommended
Python: Installation
There are two ways to install Python:
Step2.2: Anaconda file distribution system consists of all the different installers; click on the
required installer
Assisted Practice: Installation of Python
Duration: 5 mins
Objective: In this demonstration, we will learn how to install Python.
Tasks to perform:
1. Log in to the URL to download python: https://www.python.org/
2. Click on the Downloads to download Python
Python IDE
Discussion
Python
Duration: 20 minutes
Why does every programming language have an IDE?
• What is an IDE?
• Is Jupyter notebook an IDE?
Python: IDE
An integrated development environment (IDE) is a software suite that consolidates basic
tools required to write and test software.
Python has the many IDEs:
PC
Top
Python
IDEs
y
Image source: https://www.javatpoint.com/python-ides
Python: Interpreter
• Python code can be written in any text editor and saved
using the “.py” extension in the system.
• Python is characterized as a REPL (Read-Eval-Print Loop)
language because of the way its interpreter works:
o Reads the command
o Executes the command
o Outputs the results
o Then, loops back to read it again (read, evaluate, print,
loop)
Python: Shell
Python can be accessed through the command prompt on the Windows OS and the terminal
window on the Mac OS.
Windows Mac
Python: Shell
Type the command python to enter the python shell
Windows Mac
Python: Shell
Enter a statement to get the expected results
Windows Mac
Python: Shell
Enter the command quit() to exit from the environment
Windows Mac
Python: Jupyter
Jupyter is a project and a community to create open-source software, open standards, and
services for interactive computing across dozens of programming languages.
Jupyter can be accessed through three main environments:
Image source : https://jupyter.org/try
Python: Jupyter Lab
The Jupyter lab can be used to access Python and has the below features:
• The most recent web-based interactive
development environment for code, data,
and notebooks is Jupyter lab.
• Users can configure and arrange
workflows in data science, scientific
computing, computational journalism, and
machine learning using the Jupyter lab.
Python: Jupyter Lab Installation
Enter the following commands to access the jupyter lab:
Step 1: Jupyter lab can be installed with pip.
pip install jupyterlab
Step 2: Once installed, launch Jupyter lab with the
below command:
jupyter-lab
Python
Duration: 20 minutes
Why does every programming language have an IDE?
• What is an IDE?
Answer: An integrated development environment (IDE) is a software suite
that consolidates the tools required to write and test software.
• Is Jupyter notebook an IDE?
Answer: Yes, Jupyter notebook is a Python IDE.
First Python Program
Python: First Program
The following is a simple Python program to print values:
• print() is a built-in function used to display a
specified message to the screen.
• The message can be:
o A string
o An integer
o any other object
• The object will be converted into a string
before being written to the screen.
Assisted Practice : First Python Program
Objective: In this demonstration, we will learn how to write and execute a simple python program
Tasks to perform:
1. Open a new notebook on Jupyter lab
2. Write and execute a program to print “Hello World!”
Python: Code Execution
A Python program can be executed in two ways:
1. A Python program can be executed by writing directly on the command line.
2. A Python program can be executed as a batch file where a python file is created on a
code editor, saved using the “.py” file extension, and then run on the command line.
Python Programming Features
Discussion
Python
Duration: 20 minutes
Is adding indentations and comments a good programming practice?
• What are indentations?
• Why are comments required?
Python: Identifier
A Python identifier is a name used to identify a variable, function, class, module, or another object.
There are few identifier naming rules which are as follows:
Identifiers can be a combination of: Special symbols like! @, #, $, % cannot
• letters in lowercase (a to z) or be used in an identifier
uppercase (A to Z)
• digits ( 0 – 9 )
• underscore ( _ ) Rules
An identifier cannot start with a digit, Keywords like global, and class cannot be
and it can be of any length. used as identifiers.
Python is case-sensitive where a is not equal to A.
Python: Identifier
Few Examples of Identifiers are as follows
Valid Identifiers are Invalid Identifiers are
• myClass, • 1variable,
• var_1, • class@new,
• count Examples • global
Python: Indentation
Indentation refers to the spaces at the beginning of a code line.
The importance of indentation in Python is provided below:
Correct Syntax
• Python's indentation is crucial, unlike in other
programming languages where it serves to make
the code easier to understand.
Incorrect Syntax • Python uses indentation to indicate a block of
code:
Example: for if … else, for loop, while loop.
• An indented block of code begins with “:”
Python: Comments
Comments are programmer-readable explanations in a program:
Example : • Comments are annotations in the source code of
a computer program.
• Comments make it easier for humans to
understand the source code.
• A comment in python starts with ‘#’ and the rest
of the line is considered a comment.
Python
Duration: 20 minutes
Is adding indentations and comments a good programming practice?
• What are indentations?
Answer: Indentation refers to the spaces at the beginning of a code line.
Python's indentation is crucial unlike in other programming languages, where
it serves to make the code easier to understand.
• Why are comments required?
Answer: Comments are programmer-readable explanations in a program.
Comments make it easier for humans to understand the source code.
Key Takeaways
Python was developed by Guido Van Rossum.
Python is an interpreted language but is a very powerful programming
language with complex data structures and reusable modules.
IDE such as JupyterLab, Atom, Spyder, and PyCharm is used to
access Python.
Python syntax is simple to use, and indentation is used to mark
the block of code.
Knowledge Check
Knowledge
Check
Python was invented by _______.
1
A. Guido Can Rossum
B. Dennis MacAlistair Ritchie
C. James Gosling
D. None of the above
Knowledge
Check
Python was invented by _______.
1
A. Guido Can Rossum
B. Dennis MacAlistair Ritchie
C. James Gosling
D. None of the above
The correct answer is A
Python was invented by Guido Can Rossum (CWI, Amsterdam.)
Knowledge
Check
The advantages of Python are:
2
A. Flexible
B. Easy to use
C. Readability
D. All of the above
Knowledge
Check
The advantages of Python are:
2
A. Flexible
B. Easy to use
C. Readability
D. All of the above
The correct answer is D
Python aids in cross-platform compatibility, uses a minimal amount of code to complete tasks, and
places a strong emphasis on readable code.
Knowledge
Check Python code can be written in any text editor and saved using the _____ extension in the
3 system.
A. .pytxt
B. .python
C. .py
D. All of the above
Knowledge
Check Python code can be written in any text editor and saved using the _____ extension in the
3 system.
A. .pytxt
B. .python
C. .py
D. All of the above
The correct answer is C
Python code can be written in any text editor and saved using the “.py” extension in the system.
Thank You