0% found this document useful (0 votes)
3 views39 pages

Introduction To Python

The document provides an introduction to Python, covering its installation, basic concepts like variables, data types, statements, and expressions, as well as comments and type casting. It also discusses the Anaconda distribution, its components, and various IDEs for Python programming. Additionally, it includes practical lab exercises and examples to illustrate Python's functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views39 pages

Introduction To Python

The document provides an introduction to Python, covering its installation, basic concepts like variables, data types, statements, and expressions, as well as comments and type casting. It also discusses the Anaconda distribution, its components, and various IDEs for Python programming. Additionally, it includes practical lab exercises and examples to illustrate Python's functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Introduction to Python

Outline

• Introduction
• Python 3.13.0 Installation
• How Python Program runs?
• Variables and Data Types
• Python Statements and Expressions
• Python Comments
• Lab#1
• Anaconda Navigator Installation

Introduction to Python
Introduction to Python

Introduction to Python
What is Python?

• Python is an open-source , general-purpose , high-level programming language


• Developed by Guido van Rossum
• Released in 1991
• Mainly used for:
• Backend Development ( Server-side programming )
• Web Development ( Django and Flask Frameworks)
• Data Analysis and Visualizations
• Machine Learning Tasks
• Deep Learning Task
• GUI
• Software Development
• Research & Development
• All other task in conventional high-level languages

Introduction to Python
Python – A huge set of Libraries for almost each
specialized task

Source :https://rotechnica.com/what-is-python-used-for/
Introduction to Python
Giants are using Python!

Source :https://rotechnica.com/what-is-python-used-for/
Introduction to Python
Reasons to choose Python ?

Open Source

Easy to Learn

Huge Library - Strong Online Community

Less Code , Large Functionalities

Code Readability

High Demand

Introduction to Python
Python Installation
• Check if python is already installed on your computer
• cmd python --version
• Visit www.python.org
• Download Python 3.13.1 / latest version for Windows
• Choose the default path
• Remember to check:  Add Python to environment variables
• After setup completes
• Again, run python --version on command prompt to verify successful installation

Introduction to Python
Starting out in Python – Hello World!
• There are various ways to run python code:
• Interactive mode ( Python shell)
• Python IDLE
• Text Editor ( Visual Studio Code)
• IDE ( PyCharm)
• Anaconda Navigator (
• Jupyter Notebook
• Jupyter Lab
• Spyder
• PyCharm
• Visual Studio Code
• We will be using Anaconda Navigator (Jupyter Notebook)
• We can also use https://colab.google/ ( Google Colab)

Introduction to Python
Hello World !
• Interactive Mode
• Open Python shell and print Hello World!
• Command Line
• Create a text file
• Print(“Hello World! )
• Save it as hello.py in your user directory
• Run this hello.py file from command line
• Python IDLE
• Print “ Hello World”
• Create a new file
• Create two variables : a=10 , b=20
• Using if statement print “ a is less than b “ or “ a is greater than b”
• Jupyter Notebook

Introduction to Python
How it Works ?

Introduction to Python
Variables and Data Types

Introduction to Python
Variables

• A variable is a named memory location which is used to store data.


• Each variable has a type which depends on the values it stores

Introduction to Python
Variables Naming Conventions
• Each variable in python has a name
• Naming Conventions:
• The first character must be one of the letters a through z, A through Z, or an
underscore character (_)
• After the first character you may use the letters a through z or A through Z, the digits 0
through 9, or underscores.
• Uppercase and lowercase characters are distinct. This means the variable name
ItemsOrdered is not the same as itemsordered
• You cannot use any of Python’s key words as a variable name.
• A variable name cannot contain spaces
• You can’t use special characters like !, @, #, $, % etc. in variable name.

Introduction to Python
Python Keywords
• Keywords have specific use in python language
• These keywords cannot be used as variable names

Introduction to Python
Python Data Types
• Data types represents the type of value ( to be stored in a variable)
• For examples :
• 10 is an integer value
• 20.5 is a floating-point value
• 10+5j is a complex number
• “Hello World” is a string value
• True and False are Boolean values
• [“python” , “Java” , “C++”] is a list of values
• There are other types as well

Introduction to Python
Python Data Types

Introduction to Python
Mutable and Immutable Data Types

• Mutable Data Types


• Those whose values can be changed in place:
1. Lists
2. Dictionaries
3. Sets
• Immutable Data Types
• Those that can never change their value in place.
1. Integers
2. Floating-Point numbers
3. Booleans
4. Strings
5. Tuples

Introduction to Python
Type Casting
• Type Casting
• A method to convert the variable data type into another data type
• There can be two types of Type Casting in Python
• Implicit Type Casting
• Explicit Type Casting
• Examples :
• a=5, b=4.5 , c=a+b , d=a*b ( what are the data types of c and d)
• int(3.1416) will give you 3
• float(3) will give you 3.0. ( a float value is stored differently than an integer)
• value=10 , str(value) will give you “10” which cannot be treated as a number now
• x=3.5 , y=int(x) will cause y= ?? and x=??

Introduction to Python
Statements and Expressions

Introduction to Python
Python Statements
• A statement is an instruction that a Python interpreter can execute
• It is a single line of execution than can be executed independently of any
other code
• For example :
• print () statement
• Assignment statement
• Conditional statement
• Loop statements
• Each python statement ends with a new line ( \n – line feed character)
• A statement can be extended to multiple lines
Addition=10+20+ \
30+40+\
50+60+70
Introduction to Python
Python Expressions
• An expression in Python is a line of code that produces some value
• It is a combination of operands and operators
• Examples
• 2+4
• A+B
• a>b ( may be True of False)
• 2+5*4
• X=a+b ( a+b is expression ; the whole thing X=a+b is a statement)

Introduction to Python
Difference Between Statement &
Expressions

Every expression in python is a statement but every statement is not an expression

Introduction to Python
Comments in Python
• Comments describe what is happening inside a program so that a person
looking at the source code does not have difficulty figuring it out.
• The Python Interpreter simply ignores the comments and does not check for
Python Syntax
• Types
• Single Line Comments
• # this is a single line comment
• Multiline comments
• Either use # sign at the beginning of each new line
• Or use triple quotes to include multiple lines

Introduction to Python
Lab#1
1. Create a new Jupyter Notebook and name it as Lab#1
2. Type and execute print(“Hello World”)
3. Create two variables a=10, b=20 and sum=a+b
a) Write above three statements in separate lines ( in a single cell) each preceded by a single line comment
b) Identify the statement and expressions in above
4. Create two more variables choice1=True and choice2 =“True”
1. Check the type of both variables choice1 and choice 2
2. Display the hexadecimal address of both choice1 and choice2
5. Create a string variable and check its type
6. Create a float variable and cast it into an int type
7. Know the shortcuts:
1. ESC+A to insert cell above the current cell
2. ESC+B to insert cell below the current cell
8. Considering the variable naming rules , do the following:
1. Create and initialize any 5 variables with valid names
2. Try to create 3 variables which violate these rules.
Introduction to Python
How it Works ( Revisited) ?

Introduction to Python
Anaconda Navigator
Installation

Introduction to Python
What is Anaconda ?

• Anaconda is a distribution of the Python programming language and R for


scientific computing including:
• Data Science
• Machine Learning Applications
• Large-scale Data Processing
• Predictive Analytics, etc.
• Aims to simplify package management and deployment.
• The distribution includes data-science packages suitable for Windows, Linux,
and macOS.
• It is developed and maintained by Anaconda, Inc., which was founded by
Peter Wang and Travis Oliphant in 2012

Introduction to Python
Anaconda Distribution

• Anaconda, Inc. product, it is also known as Anaconda Distribution


• Different Products:
• Anaconda Individual Edition ( Free)
• Anaconda Team Edition ( Commercial)
• Anaconda Enterprise Edition (Commercial)
• Anaconda distribution comes with over 250 packages automatically installed,
and over 7,500 additional open-source packages which can be installed based
on need
• It also includes a GUI, Anaconda Navigator, as a graphical alternative to the
command-line interface (CLI).

Introduction to Python
Anaconda Navigator
• Anaconda Navigator is a desktop graphical user interface (GUI) included in
Anaconda distribution
• The following applications are available by default in Navigator:
• JupyterLab
• Jupyter Notebook
• QtConsole
• Spyder
• Glue
• Orange
• RStudio
• Visual Studio Code

Introduction to Python
Anaconda Individual Edition - Installation
• https://problemsolvingwithpython.com/01-Orientation/01.03-Installing-Anac
onda-on-Windows/
• https://www.tutorialspoint.com/sdlc/sdlc_quick_guide.htm

Introduction to Python
A Brief Description of Python IDEs /
Editors
Jupyter Notebook Jupyter Notebook (formerly IPython Notebook) is a web-based interactive computational environment
for creating notebook documents. ( Wikipedia)

Jupyter Lab JupyterLab is the next generation of the Jupyter Notebook. It aims at fixing many usability issues of the
Notebook, and it greatly expands its scope. JupyterLab offers a general framework for interactive
computing and data science in the browser, using Python, Julia, R, or one of many other languages. (
Source)
Spyder Spyder is an open-source cross-platform integrated development environment (IDE) for scientific
programming in the Python language. (Wikipedia)

PyCharm PyCharm is a dedicated Python Integrated Development Environment (IDE) providing a wide range of
essential tools for Python developers, tightly integrated to create a convenient environment for
productive Python, web, and data science development. (Wikipedia)

Visual Studio Code Visual Studio Code, also commonly referred to as VS Code, is a source-code editor made by Microsoft
for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent
code completion, snippets, code refactoring, and embedded Git (Wikipedia)

Introduction to Python
A Brief Comparison of Python IDEs/
Editors

Source
Introduction to Python
Resources
• Starting out with Python (Textbook)
• Chapter 1 and Chapter 2
• https://pynative.com

Introduction to Python
Python Math Operators

Introduction to Python Spring 2025 35


Python Math Operators

Introduction to Python Spring 2025 36


Example

Introduction to Python
Example
1) Suppose a retail business is planning to have a storewide sale where the prices of all items will
be 20 percent off. We have been asked to write a program to calculate the sale price of an
item after the discount is subtracted.
Program Output
Enter the item's original price: 100.00
The sale price is 80.0
2) Suppose you have taken three tests in your computer science class, and you want to write a
program that will display the average of the test scores.
Enter the first test score: 90
Enter the second test score: 80
Enter the third test score: 100
Enter The average score is 90.0

Introduction to Python Spring 2025 38


Example

Introduction to Python Spring 2025 39

You might also like