10/1/23
PYTHON & VIRTUAL ENVIRONMENT
An Introduction
INTRODUCTION TO PYTHON &
VIRTUAL ENVIRONMENT
WHAT ARE WE GOING TO LEARN TODAY?
Ø Python Language
o History of Python
o What is Python?
o Why Python
Ø Python Integrated Development Environment (IDE)
Ø Virtual Environment
o What is Virtual Environment?
o Why We Need Virtual Environment?
Ø Introduction to Python
o Basic Syntax, Variables, Data Types
o Lists
o Dictionaries
o Basic Operators
Ø Hands-On
1
10/1/23
PYTHON
LANGUAGE
HISTORY OF PYTHON
Python was created in the late 1980s by Guido van Rossum at
Centrum Wiskunde & Informatica (CWI) in the Netherlands.
Guido Van Rossum posted the code (labelled version 0.9.0) to
alt.sources in February 1991.
Guido van Rossum
Python versions are python 1, python 2 and python 3.
The ABC programming language is thought to be the forerunner
of Python, as it was capable of handling exceptions and
interacting with the Amoeba Operating System.
ABC language and Modula -3 are programming language that
influence python.
2
10/1/23
WHAT IS PYTHON?
High level, powerful, open-source and
01
popular programming language.
Python provides support for modules and
02 packages, which promotes programme
modularity and code reuse.
The Python interpreter and extensive
03 standard library are freely distributable
and available in source or binary form for
all major platforms.
WHY PYTHON
Simple and easy to learn
It uses simplified syntax with
an emphasis on natural
language.
3
10/1/23
WHY PYTHON
Portable and extensible
It is supported by most of
platforms in use today
WHY PYTHON
More productive
Code can be written in fewer lines
4
10/1/23
PURPOSE OF PYTHON
Solve
Build web Academic Build a
business
application research game
problem
APPLICATION THAT USES PYTHON
Google
Spotify Pinterest
Netflix Instagram Dropbox
10
5
10/1/23
PYTHON POPULARITY (TIOBE INDEX)
11
INTEGRATED
DEVELOPMENT
ENVIRONMENT
(IDE)
12
6
10/1/23
PYTHON IDE
An IDE (or Integrated Development Environment) is a program dedicated to software development
13
VIRTUAL
ENVIRONMENT
14
7
10/1/23
WHAT IS VIRTUAL ENVIRONMENT?
Ø A virtual environment is a tool that helps to keep dependencies required by different projects
separate by creating isolated python virtual environments
15
WHY WE NEED VIRTUAL ENVIRONMENT?
Ø Python has various modules and packages
for different applications. Our project may
require a third-party library
Ø To make a separate isolated environment.
Each project can store and retrieve packages
from their specific environment
Ø Easier to maintain the dependencies required
in created project
Ø Easier to deploy / put the project on
production site (minimize dependencies
conflict)
16
8
10/1/23
INTRODUCTION
TO PYTHON
17
BASIC SYNTAX
Basic Syntax Description
Print(“______”) Print statement
Indentation ü Use in function, loop and conditional
statement
if True: ü One single tab for single indent level
print("Inside True")
print("Will throw error because of extra whitespace")
else:
print("False")
Comments Inclusion of short descriptions along with the
code to increase its readability
# - Single line comments
“”” (delimiter) – Multi line comments
18
9
10/1/23
VARIABLES
Ø Variable is a name that is used to refer to memory location. Python variable is also known as
an identifier and used to hold value
Ø In Python, no need to specify the type of variable because Python is an infer language and
smart enough to get variable type
Ø Variable names can be a group of both the letters and digits, but they have to begin with a
letter or an underscore
Ø Recommended to use lowercase letters for the variable name. ie. Rahul and Rahul both are
two different variables
19
VARIABLES (CONT)
Ø Rules to name an identifier for variable are given below:
a. The first character of the variable must be an alphabet or underscore _
b. All the characters except the first character may be an alphabet of lower case (a – z),
upper case (A – Z), underscore or digit (0 – 9)
c. Identifier must not contain any white-space or special character (!, @, #, %, ^, %, *)
d. Identifier must not be similar to any keyword defined in the language
e. Identifier names are case sensitive; for example: my name and MyName is not the same
20
10
10/1/23
VARIABLES (CONT)
Example valid and invalid identifier
Valid Identifier Invalid Identifier
num1 1name
FLAG num#
get_user_name True
userDetails def
_1234 @my.name
my_name for
21
VARIABLES (CONT)
Reserved Keyword in Python
cannot be used for identifier!
22
11
10/1/23
VARIABLES (CONT)
Ø The equal sign ( = ) is used to assign values to variables
Ø The operand to the left of the = operator is the name of the variable and the operand to the
right of the = operator is the value stored in the variable
Name_of_the_variable = Value_to_variable
23
DATA TYPES
24
12
10/1/23
VARIABLES & DATA TYPES
Here are some rules when naming variables in Python:
1. Names must contain only letters, numbers and underscores.
This is the correct way to
declare a variable in Python.
Adding a
period (.) in Python reads
front of a my as a
character in variable, and
Python is string1 as a
known as a Python method.
method.
25
VARIABLES & DATA TYPES
Here are some rules when naming variables in Python:
2. Spaces are not allowed.
This is the correct way to
declare a variable in Python.
Python will
inform that the
syntax is
incorrect.
26
13
10/1/23
VARIABLES & DATA TYPES
Here, we’re assigning a string “Hello
world!” to the variable message. We
then print out this message.
We can use the type() function to
check the variable’s data type.
27
LISTS
Ø Lists are a collection of basic data types (also known as array)
Ø List can be declared using square brackets and items can be added inside the brackets using
comma separation
1 3 2 9 8 2 3 Element at index 5
First index 0 1 2 3 4 5 6 Last index
Array length is 7
28
14
10/1/23
LISTS (CONT)
The contents of the list
are enclosed inside
square brackets. This is
how you create a list.
Access the elements of
the list using the
indexing method. Python
indexing begins at 0.
29
LISTS (CONT)
You can also apply
string methods on
list elements
Apply .title() method on the
second element in the list, and
print a message using this
method.
30
15
10/1/23
LISTS (CONT)
Ø Removing elements from lists
Ø Organizing a lists
Ø Slicing/subsetting a lists
Ø Looping through a lists
Ø Copying a lists
Reference: https://www.w3schools.com/python/python_lists.asp
31
DICTIONARIES
Ø Dictionaries are python’s implementation of a data structure that is more generally known as
an associative array
Ø There are 2 elements of a dictionary:
1. Key
2. Value
Ø Curly bracket can be used to write dictionaries, with the key and value separated by a colon
and the items separated by commas
32
16
10/1/23
DICTIONARIES (CONT)
Value
Key
33
DICTIONARIES (CONT)
To access the values of the dictionary, we
provide the name of the dictionary
(patient_information) followed by the
name of the key (name and/or age)
enclosed in quotation marks and in square
brackets.
34
17
10/1/23
DICTIONARIES (CONT)
We can use the values in the dictionary
to print out a message. Here, we’re
printing out the name of the patient.
35
DICTIONARIES (CONT)
If we want to add new key-value pairs to the
dictionary, we specify the name of the
dictionary, followed by the key name and the Here, we add new elements:
the patient’s address and
its associated value pair.
medical diagnosis.
36
18
10/1/23
BASIC OPERATORS
Operators are special symbols in Python that carry out arithmetic
or logical computation. The value that the operator operates on is
called the operand.
This is an operator
These are
operands.
37
BASIC OPERATORS (CONT)
1. Arithmetic operators: Used to perform mathematical operations such as
addition, subtraction, multiplication, etc.
2. Assignment operators: Used to assign values to variables
3. Comparison operators: Used to compare values. Returns either True or False.
4. Logical operators: Used to combine conditional statements
5. Membership operators: Used to test whether a value/variable is found in a
sequence of string, list, tuple, set or dictionary.
38
19
10/1/23
BASIC OPERATORS (CONT)
Arithmetic
operators
Comparison
operators
39
BASIC OPERATORS (CONT)
Membership operators
Logical operators
40
20
10/1/23
BASIC OPERATORS (CONT)
• Python Operators
• https://www.w3schools.com/python/python_operators.asp
• https://www.tutorialspoint.com/python/python_basic_operators.htm
• https://www.programiz.com/python-programming/operators
41
THANK YOU
42
21