SlideShare a Scribd company logo
3
Most read
4
Most read
20
Most read
Introduction to Python
What is Python?
• Python is a popular programming language. It was created by
Guido van Rossum, and released in 1991.
• It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
• Data Science
What Can Python Do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• 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.
• Python can be used for rapid prototyping, or for production-ready
software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has a 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.
• Python can be treated in a procedural, object-oriented, or
functional way.
Python Syntax vs Other programming
Languages
• Python was designed for readability and has some similarities to the
English language with influence from mathematics.
• Python uses new lines to complete a command, as opposed to other
programming languages, which often use semicolons or parentheses.
• 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.
Python Syntax
• Python syntax can be executed by writing directly in the Command
Line
• Or by creating a python file on the server, using the .py file extension,
and running it in the Command Line
Comments in Python
• Comments are an integral part of any
program
• Single-line comments: indicate what a
section of code does
• Start with # sign
• # This is a comment
7
Comments in Python
• Multi-line comments or paragraphs: serve as documentation
• Press the return key after each line, add a new hash mark and continue
your comment
# This is a pretty good example
# of how you can spread comments
# over multiple lines in Python
• Wrap multiple lines comment inside a set of tri
"""
If I really hate pressing `enter` and
typing all those hash marks, I could
just do this instead
"""
8
Comments in Python: Practices
• Avoid redundancy: Don’t repeat your self; code
should have little to no redundacy
• # print hello world
print (“ Hello World”)
• Avoid Rude comments
• Use obvious names to variables
9
Comments in Python: Practices
• If you spend too much time
explaining what you did, you need
to refactor to make your code
clearer and more concise.
10
cosc175/data 11
Variables and Constants
• constant
• alphabetic or numeric value that never changes
during processing
• can be any data type
• can also be used for something that may change
at a later date
• need only be changed in one place
• written in all capital letters and underscores
separating the words.
• PI = 3.14
• MD_TAX_RATE = .06
• variable - value does change during process
12
Identifiers: variable names
• Corresponds to memory location or address
• Naming convention varies from language to language
• a sequence of letters (a-z, A-Z), underscores (_), and digits
(0–9), and must start with a letter or an underscore.
• No spaces in variable names
• any number of characters
• Python is case sensitive
• Cat # cat
• Never use special symbols like !, @, #, $, %, etc.
• Don't start name with a digit.
• meaningful names: hrsWorked, payRate
• Be consistent
13
Assignment operator
=
• Value assigning differs from equality
• variable = expression
variable = expression
• variable -physical location in computer memory
• expression
• constant
x = 10;
x = PI;
• another variable to which a value has previously been assigned
y = x;
• a formula to be evaluated
y = a* x /2 + 3;
14
15
assignment
• Processor evaluates the right member of an assignment
statement to get a single value
• it places this value in the memory location (variable
name) given as the left member.
• Not a mathematical equation, can't be switched
stamp = 14 is a valid assignment statement
14 = stamp is not
• The left member of an assignment statement must
always be the name of a computer memory location
(variable name). It cannot be a constant or formula.
16
Assignment Statement What happens in memory
numHours = 10; the value 10 is placed in the memory location
numWidgets
numHours = numHours + 1; numWidget is evaluated. Contains a 10, one is
added to 10, 11 is stored at the memory location
numWidgets
name = "toby" the four characters t-o-b-y are stored in the
memory location name
(note: The single quotes are used as
delimiters and are not stored in memory.)
stuff = numHours; Assuming the value 11 in the memory
location numWidgets, this assignment
statement places the value 11 in stuff
(note: Now both stuff and numWidgets have
the same value.)
hours = numHours * 2 the ALU evaluates the expression on the right
and places the value 30 in the memory
location widget
17
Assignment Statement What happens in memory
numHours = 10; the value 10 is placed in the memory location
numHours
numHours = numHours + 1; numHours is evaluated. Contains a 10, one is
added to 10, 11 is stored at the memory location
numHours
name = "toby" the four characters t-o-b-y are stored in the
memory location name
(note: The single quotes are used as
delimiters and are not stored in memory.)
stuff = numHours; Assuming the value 11 in the memory
location numHours, this assignment
statement places the value 11 in stuff
(note: Now both stuff and numHours have
the same value.)
hours = numHours * 2 the ALU evaluates the expression on the right
and places the value 30 in the memory
location hours
Assignment Operators
18
cosc175/operators 19
Modules in Python
• Module: A module is a file containing Python code that can
be used by other modules or scripts.
• A module is made available for use via the import
statement.
• Once a module is imported, any object defined in that
module can be accessed using dot notation.
• import math
• math.pow(2, 4)
20
Relational Operators
op operation
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
<> Different from
21
Logical Operators

More Related Content

PDF
Basic Concepts in Python
PPTX
Python programming
PDF
python notes.pdf
PDF
Python decision making
PPTX
Boolean and conditional logic in Python
PPTX
Variables in python
Basic Concepts in Python
Python programming
python notes.pdf
Python decision making
Boolean and conditional logic in Python
Variables in python

What's hot (20)

PPSX
Programming with Python
PPTX
Python Datatypes by SujithKumar
PDF
Python Modules
PPT
Input and output in C++
PPTX
Python Functions
PPTX
Functions in c
PPTX
Java String Handling
PPTX
Introduction to the basics of Python programming (part 1)
PDF
Python strings
PPTX
Operators in python
PDF
Lesson 03 python statement, indentation and comments
PPTX
C Structures and Unions
PPTX
Python basics
PDF
Python programming : Standard Input and Output
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PPT
Introduction to Basic C programming 01
PPTX
Java applet - java
PPTX
PDF
Introduction to Python
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
Programming with Python
Python Datatypes by SujithKumar
Python Modules
Input and output in C++
Python Functions
Functions in c
Java String Handling
Introduction to the basics of Python programming (part 1)
Python strings
Operators in python
Lesson 03 python statement, indentation and comments
C Structures and Unions
Python basics
Python programming : Standard Input and Output
Interface in java ,multiple inheritance in java, interface implementation
Introduction to Basic C programming 01
Java applet - java
Introduction to Python
CONDITIONAL STATEMENT IN C LANGUAGE
Ad

Similar to Lecture Introduction to Python 2024.pptx (20)

PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PDF
Class_X_PYTHON_J.pdf
PDF
Python_Programming_PPT Basics of python programming language
PPTX
Python unit 2 is added. Has python related programming content
PPTX
UNIT 1 .pptx
PDF
Python Module-1.1.pdf
PPTX
Unit -1 CAP.pptx
PPTX
Python fundamentals
PPTX
Python 01.pptx
PPTX
Introduction to Python Basics for PSSE Integration
PDF
Python (3).pdf
PPTX
Python Demo.pptx
PPTX
unit1 python.pptx
PPTX
Python Demo.pptx
PPTX
python introduction initial lecture unit1.pptx
PPTX
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
PDF
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
PPT
notwa dfdfvs gf fdgfgh s thgfgh frg reggg
PPTX
modul-python-all.pptx
PDF
Python basic programing language for automation
Basic concept of Python.pptx includes design tool, identifier, variables.
Class_X_PYTHON_J.pdf
Python_Programming_PPT Basics of python programming language
Python unit 2 is added. Has python related programming content
UNIT 1 .pptx
Python Module-1.1.pdf
Unit -1 CAP.pptx
Python fundamentals
Python 01.pptx
Introduction to Python Basics for PSSE Integration
Python (3).pdf
Python Demo.pptx
unit1 python.pptx
Python Demo.pptx
python introduction initial lecture unit1.pptx
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
notwa dfdfvs gf fdgfgh s thgfgh frg reggg
modul-python-all.pptx
Python basic programing language for automation
Ad

Recently uploaded (20)

PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
High Ground Student Revision Booklet Preview
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
English Language Teaching from Post-.pdf
PDF
Landforms and landscapes data surprise preview
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
Congenital Hypothyroidism pptx
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
IMMUNIZATION PROGRAMME pptx
PDF
Types of Literary Text: Poetry and Prose
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Open Quiz Monsoon Mind Game Prelims.pptx
High Ground Student Revision Booklet Preview
Cardiovascular Pharmacology for pharmacy students.pptx
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
English Language Teaching from Post-.pdf
Landforms and landscapes data surprise preview
The Final Stretch: How to Release a Game and Not Die in the Process.
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
Congenital Hypothyroidism pptx
Onica Farming 24rsclub profitable farm business
IMMUNIZATION PROGRAMME pptx
Types of Literary Text: Poetry and Prose
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx

Lecture Introduction to Python 2024.pptx

  • 2. What is Python? • Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. • It is used for: • web development (server-side), • software development, • mathematics, • system scripting. • Data Science
  • 3. What Can Python Do? • Python can be used on a server to create web applications. • Python can be used alongside software to create workflows. • 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. • Python can be used for rapid prototyping, or for production-ready software development.
  • 4. Why Python? • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). • Python has a simple syntax similar to the English language. • Python has a 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. • Python can be treated in a procedural, object-oriented, or functional way.
  • 5. Python Syntax vs Other programming Languages • Python was designed for readability and has some similarities to the English language with influence from mathematics. • Python uses new lines to complete a command, as opposed to other programming languages, which often use semicolons or parentheses. • 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.
  • 6. Python Syntax • Python syntax can be executed by writing directly in the Command Line • Or by creating a python file on the server, using the .py file extension, and running it in the Command Line
  • 7. Comments in Python • Comments are an integral part of any program • Single-line comments: indicate what a section of code does • Start with # sign • # This is a comment 7
  • 8. Comments in Python • Multi-line comments or paragraphs: serve as documentation • Press the return key after each line, add a new hash mark and continue your comment # This is a pretty good example # of how you can spread comments # over multiple lines in Python • Wrap multiple lines comment inside a set of tri """ If I really hate pressing `enter` and typing all those hash marks, I could just do this instead """ 8
  • 9. Comments in Python: Practices • Avoid redundancy: Don’t repeat your self; code should have little to no redundacy • # print hello world print (“ Hello World”) • Avoid Rude comments • Use obvious names to variables 9
  • 10. Comments in Python: Practices • If you spend too much time explaining what you did, you need to refactor to make your code clearer and more concise. 10
  • 11. cosc175/data 11 Variables and Constants • constant • alphabetic or numeric value that never changes during processing • can be any data type • can also be used for something that may change at a later date • need only be changed in one place • written in all capital letters and underscores separating the words. • PI = 3.14 • MD_TAX_RATE = .06 • variable - value does change during process
  • 12. 12 Identifiers: variable names • Corresponds to memory location or address • Naming convention varies from language to language • a sequence of letters (a-z, A-Z), underscores (_), and digits (0–9), and must start with a letter or an underscore. • No spaces in variable names • any number of characters • Python is case sensitive • Cat # cat • Never use special symbols like !, @, #, $, %, etc. • Don't start name with a digit. • meaningful names: hrsWorked, payRate • Be consistent
  • 13. 13 Assignment operator = • Value assigning differs from equality • variable = expression
  • 14. variable = expression • variable -physical location in computer memory • expression • constant x = 10; x = PI; • another variable to which a value has previously been assigned y = x; • a formula to be evaluated y = a* x /2 + 3; 14
  • 15. 15 assignment • Processor evaluates the right member of an assignment statement to get a single value • it places this value in the memory location (variable name) given as the left member. • Not a mathematical equation, can't be switched stamp = 14 is a valid assignment statement 14 = stamp is not • The left member of an assignment statement must always be the name of a computer memory location (variable name). It cannot be a constant or formula.
  • 16. 16 Assignment Statement What happens in memory numHours = 10; the value 10 is placed in the memory location numWidgets numHours = numHours + 1; numWidget is evaluated. Contains a 10, one is added to 10, 11 is stored at the memory location numWidgets name = "toby" the four characters t-o-b-y are stored in the memory location name (note: The single quotes are used as delimiters and are not stored in memory.) stuff = numHours; Assuming the value 11 in the memory location numWidgets, this assignment statement places the value 11 in stuff (note: Now both stuff and numWidgets have the same value.) hours = numHours * 2 the ALU evaluates the expression on the right and places the value 30 in the memory location widget
  • 17. 17 Assignment Statement What happens in memory numHours = 10; the value 10 is placed in the memory location numHours numHours = numHours + 1; numHours is evaluated. Contains a 10, one is added to 10, 11 is stored at the memory location numHours name = "toby" the four characters t-o-b-y are stored in the memory location name (note: The single quotes are used as delimiters and are not stored in memory.) stuff = numHours; Assuming the value 11 in the memory location numHours, this assignment statement places the value 11 in stuff (note: Now both stuff and numHours have the same value.) hours = numHours * 2 the ALU evaluates the expression on the right and places the value 30 in the memory location hours
  • 19. cosc175/operators 19 Modules in Python • Module: A module is a file containing Python code that can be used by other modules or scripts. • A module is made available for use via the import statement. • Once a module is imported, any object defined in that module can be accessed using dot notation. • import math • math.pow(2, 4)
  • 20. 20 Relational Operators op operation < Less than <= Less than or equal to > Greater than >= Greater than or equal to == Equal to != Not equal to <> Different from