SlideShare a Scribd company logo
1.1 Introduction to Python
1ARULKUMAR V AP/CSE SECE
Objectives
2
 To write and run a simple Python program.
 To explain the basic syntax of a Python program (§1.5).
 To describe the history of Python (§1.6).
 To explain the importance of, and provide examples of,
proper programming style and documentation (§1.7).
 To explain the differences between syntax errors,
runtime errors, and logic errors (§1.8).
 To create a basic graphics program using Turtle (§1.9).
ARULKUMAR V AP/CSE SECE
What is Python?
General Purpose Interpreted Object-Oriented
3
Python is a general purpose programming language.
That means you can use Python to write code for
any programming tasks. Python are now used in
Google search engine, in mission critical projects in
NASA, in processing financial transactions at New
York Stock Exchange.
ARULKUMAR V AP/CSE SECE
What is Python?
General Purpose Interpreted Object-Oriented
4
Python is interpreted, which means that python
code is translated and executed by an interpreter
one statement at a time. In a compiled language, the
entire source code is compiled and then executed
altogether.
ARULKUMAR V AP/CSE SECE
What is Python?
General Purpose Interpreted Object-Oriented
5
Python is an object-oriented programming
language. Data in Python are objects created from
classes. A class is essentially a type that defines the
objects of the same kind with properties and
methods for manipulating objects. Object-oriented
programming is a powerful tool for developing
reusable software.
ARULKUMAR V AP/CSE SECE
Python’s History
• created by Guido van Rossum in Netherlands in
1990
• Open source
6ARULKUMAR V AP/CSE SECE
Python 2 vs. Python 3
Python 3 is a newer version, but it is not
backward compatible with Python 2. That
means if you write a program using Python
2, it may not work on Python 3.
7ARULKUMAR V AP/CSE SECE
Launch Python
8ARULKUMAR V AP/CSE SECE
Launch Python IDLE
9ARULKUMAR V AP/CSE SECE
Run Python Script
10ARULKUMAR V AP/CSE SECE
A Simple Python Program
# Display two messages
print("Welcome to Python")
print("Python is fun")
11
Run
Welcome
Listing 1.1
IMPORTANT NOTE:
(1) To enable the buttons, you must download the entire slide
file slide.zip and unzip the files into a directory (e.g.,
c:slide). (2) You must have installed Python and set python
bin directory in the environment path. (3) If you are using
Office 2010, check PowerPoint2010.doc located in the
same folder with this ppt file.
ARULKUMAR V AP/CSE SECE
Creating and Editing Using Notepad
To use Notepad, type
notepad Welcome.py
from the DOS prompt.
12ARULKUMAR V AP/CSE SECE
Trace a Program Execution
13
# Display two messages
print("Welcome to Python")
print("Python is fun")
Execute a statement
animation
ARULKUMAR V AP/CSE SECE
Trace a Program Execution
14
# Display two messages
print("Welcome to Python")
print("Python is fun")
Execute a statement
animation
ARULKUMAR V AP/CSE SECE
Two More Simple Examples
15
RunWelcomeWithThreeMessages
RunComputeExpression
ARULKUMAR V AP/CSE SECE
Supplements on the
Companion Website
• See Supplement I.B for installing and
configuring Python
• See Supplement I.C for developing Python
programs from Eclipse
www.cs.armstrong.edu/liang/py
16
Companion
Website
ARULKUMAR V AP/CSE SECE
Anatomy of a Python Program
• Statements
• Comments
• Indentation
17ARULKUMAR V AP/CSE SECE
Statement
A statement represents an action or a sequence of
actions. The statement print("Welcome to Python") in
the program in Listing 1.1 is a statement to display the
greeting "Welcome to Python“.
18
# Display two messages
print("Welcome to Python")
print("Python is fun")
ARULKUMAR V AP/CSE SECE
Indentation
The indentation matters in Python. Note that the
statements are entered from the first column in
the new line. It would cause an error if the
program is typed as follows:
19
# Display two messages
print("Welcome to Python")
print("Python is fun")
ARULKUMAR V AP/CSE SECE
Special Symbols
20
Character Name Description
()
#
" "
''' '''
Opening and closing
parentheses
Pound sign
Opening and closing
quotation marks
Opening and closing
quotation marks
Used with functions.
Precedes a comment line.
Enclosing a string (i.e., sequence of characters).
Enclosing a paragraph comment.
ARULKUMAR V AP/CSE SECE
Programming Style and
Documentation
• Appropriate Comments
• Proper Indentation and Spacing
Lines
21ARULKUMAR V AP/CSE SECE
Appropriate Comments
Include a summary at the beginning of the
program to explain what the program does, its key
features, its supporting data structures, and any
unique techniques it uses.
Include your name, class section, instructor, date,
and a brief description at the beginning of the
program.
22ARULKUMAR V AP/CSE SECE
Proper Indentation and Spacing
• Indentation
– Indent four spaces.
– A consistent spacing style makes programs clear
and easy to read, debug, and maintain.
• Spacing
– Use blank line to separate segments of the
code.
23ARULKUMAR V AP/CSE SECE
Programming Errors
• Syntax Errors
– Error in code construction
• Runtime Errors
– Causes the program to abort
• Logic Errors
– Produces incorrect result
24ARULKUMAR V AP/CSE SECE
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
25
GUI is a great pedagogical tool to motivate studetns
and stimulate student interests in programming.
ARULKUMAR V AP/CSE SECE
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
26
A simple way to start graphics programming is to
use Python built-in Turtle package.
Run
A Turtule Example
ARULKUMAR V AP/CSE SECE
Getting Started with GUI Programming
Why GUI? Turtle Tkniter
27
Later in the book, we will also introduce Tkinter for
developing comprehensive GUI applications.
Run
A Tkinter Example
ARULKUMAR V AP/CSE SECE

More Related Content

PPT
Technical writing lecture
PPTX
Python basic
PPTX
Python-00 | Introduction and installing
PPTX
PROBLEM SOLVING TECHNIQUES USING PYTHON.pptx
PPT
Coding Standards & Best Practices for iOS/C#
PPTX
C Tokens
PDF
Python programming
PPT
Introduction to Compiler
Technical writing lecture
Python basic
Python-00 | Introduction and installing
PROBLEM SOLVING TECHNIQUES USING PYTHON.pptx
Coding Standards & Best Practices for iOS/C#
C Tokens
Python programming
Introduction to Compiler

What's hot (20)

PPTX
Function template
PPTX
Python final presentation kirti ppt1
PPTX
Decision making and branching in c programming
PPTX
1-introduction-to-dart-programming.pptx
PDF
Python course syllabus
PDF
Teach your kids how to program with Python and the Raspberry Pi
PDF
Python made easy
PPTX
python conditional statement.pptx
PDF
Function in Python
PDF
MNE-Python Coregistration
PDF
Article writing a step by step guide
PPTX
Python training
PPT
How to write exposition
PPTX
Basic Python Programming: Part 01 and Part 02
PPT
Chapter 9 Value-Returning Functions
PPTX
Password locker project
PPTX
Audience recognition and involvement
PDF
Overview of python 2019
PPT
Introduction to python
PPT
Brainstorming techniques
Function template
Python final presentation kirti ppt1
Decision making and branching in c programming
1-introduction-to-dart-programming.pptx
Python course syllabus
Teach your kids how to program with Python and the Raspberry Pi
Python made easy
python conditional statement.pptx
Function in Python
MNE-Python Coregistration
Article writing a step by step guide
Python training
How to write exposition
Basic Python Programming: Part 01 and Part 02
Chapter 9 Value-Returning Functions
Password locker project
Audience recognition and involvement
Overview of python 2019
Introduction to python
Brainstorming techniques
Ad

Similar to 1. introduction to python (20)

PDF
Chapter 1 - Basic concepts of programming.pdf
PDF
Java lab1 manual
DOCX
(D 15 180770107240)
PDF
Socket programming-in-python
PDF
Programming in Java: Getting Started
PDF
Python_final_print_vison_academy_9822506209.pdf
PPTX
Programming
PDF
Python PPT1.pdf
PDF
ProgFund_Lecture_7_Intro_C_Sequence.pdf
PPT
Python Intro For Managers
PPTX
Introduction to programming
PDF
Python_final_print_batch_II_vision_academy.pdf
PDF
Python_final_print_batch_II_vision_academy.pdf
PDF
Python_vision_academy notes
PDF
Python_final_print_batch_II_vision_academy.pdf
PDF
Python_final_print_batch_II_vision_academy (1).pdf
PDF
Learning python in a cool and fun way-Module-1.1.pdf
PDF
Core python programming tutorial
PDF
C tutorials
Chapter 1 - Basic concepts of programming.pdf
Java lab1 manual
(D 15 180770107240)
Socket programming-in-python
Programming in Java: Getting Started
Python_final_print_vison_academy_9822506209.pdf
Programming
Python PPT1.pdf
ProgFund_Lecture_7_Intro_C_Sequence.pdf
Python Intro For Managers
Introduction to programming
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
Python_vision_academy notes
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy (1).pdf
Learning python in a cool and fun way-Module-1.1.pdf
Core python programming tutorial
C tutorials
Ad

More from PhD Research Scholar (20)

PPTX
Quiz servlet
PPTX
servlet db connectivity
PPTX
2.java script dom
PPTX
1.java script
PPTX
Quiz javascript
PPTX
Thread&multithread
PPTX
Streams&io
PPTX
PPTX
Interface in java
PPTX
Inner classes in java
PPTX
PPTX
Exception handling
PPTX
Abstract class
PPTX
7. tuples, set & dictionary
PPTX
Quiz servlet
servlet db connectivity
2.java script dom
1.java script
Quiz javascript
Thread&multithread
Streams&io
Interface in java
Inner classes in java
Exception handling
Abstract class
7. tuples, set & dictionary

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Trump Administration's workforce development strategy
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PDF
O7-L3 Supply Chain Operations - ICLT Program
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Complications of Minimal Access Surgery at WLH
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
VCE English Exam - Section C Student Revision Booklet
Trump Administration's workforce development strategy
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
O7-L3 Supply Chain Operations - ICLT Program
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Pharma ospi slides which help in ospi learning
Microbial diseases, their pathogenesis and prophylaxis
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program

1. introduction to python

  • 1. 1.1 Introduction to Python 1ARULKUMAR V AP/CSE SECE
  • 2. Objectives 2  To write and run a simple Python program.  To explain the basic syntax of a Python program (§1.5).  To describe the history of Python (§1.6).  To explain the importance of, and provide examples of, proper programming style and documentation (§1.7).  To explain the differences between syntax errors, runtime errors, and logic errors (§1.8).  To create a basic graphics program using Turtle (§1.9). ARULKUMAR V AP/CSE SECE
  • 3. What is Python? General Purpose Interpreted Object-Oriented 3 Python is a general purpose programming language. That means you can use Python to write code for any programming tasks. Python are now used in Google search engine, in mission critical projects in NASA, in processing financial transactions at New York Stock Exchange. ARULKUMAR V AP/CSE SECE
  • 4. What is Python? General Purpose Interpreted Object-Oriented 4 Python is interpreted, which means that python code is translated and executed by an interpreter one statement at a time. In a compiled language, the entire source code is compiled and then executed altogether. ARULKUMAR V AP/CSE SECE
  • 5. What is Python? General Purpose Interpreted Object-Oriented 5 Python is an object-oriented programming language. Data in Python are objects created from classes. A class is essentially a type that defines the objects of the same kind with properties and methods for manipulating objects. Object-oriented programming is a powerful tool for developing reusable software. ARULKUMAR V AP/CSE SECE
  • 6. Python’s History • created by Guido van Rossum in Netherlands in 1990 • Open source 6ARULKUMAR V AP/CSE SECE
  • 7. Python 2 vs. Python 3 Python 3 is a newer version, but it is not backward compatible with Python 2. That means if you write a program using Python 2, it may not work on Python 3. 7ARULKUMAR V AP/CSE SECE
  • 11. A Simple Python Program # Display two messages print("Welcome to Python") print("Python is fun") 11 Run Welcome Listing 1.1 IMPORTANT NOTE: (1) To enable the buttons, you must download the entire slide file slide.zip and unzip the files into a directory (e.g., c:slide). (2) You must have installed Python and set python bin directory in the environment path. (3) If you are using Office 2010, check PowerPoint2010.doc located in the same folder with this ppt file. ARULKUMAR V AP/CSE SECE
  • 12. Creating and Editing Using Notepad To use Notepad, type notepad Welcome.py from the DOS prompt. 12ARULKUMAR V AP/CSE SECE
  • 13. Trace a Program Execution 13 # Display two messages print("Welcome to Python") print("Python is fun") Execute a statement animation ARULKUMAR V AP/CSE SECE
  • 14. Trace a Program Execution 14 # Display two messages print("Welcome to Python") print("Python is fun") Execute a statement animation ARULKUMAR V AP/CSE SECE
  • 15. Two More Simple Examples 15 RunWelcomeWithThreeMessages RunComputeExpression ARULKUMAR V AP/CSE SECE
  • 16. Supplements on the Companion Website • See Supplement I.B for installing and configuring Python • See Supplement I.C for developing Python programs from Eclipse www.cs.armstrong.edu/liang/py 16 Companion Website ARULKUMAR V AP/CSE SECE
  • 17. Anatomy of a Python Program • Statements • Comments • Indentation 17ARULKUMAR V AP/CSE SECE
  • 18. Statement A statement represents an action or a sequence of actions. The statement print("Welcome to Python") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Python“. 18 # Display two messages print("Welcome to Python") print("Python is fun") ARULKUMAR V AP/CSE SECE
  • 19. Indentation The indentation matters in Python. Note that the statements are entered from the first column in the new line. It would cause an error if the program is typed as follows: 19 # Display two messages print("Welcome to Python") print("Python is fun") ARULKUMAR V AP/CSE SECE
  • 20. Special Symbols 20 Character Name Description () # " " ''' ''' Opening and closing parentheses Pound sign Opening and closing quotation marks Opening and closing quotation marks Used with functions. Precedes a comment line. Enclosing a string (i.e., sequence of characters). Enclosing a paragraph comment. ARULKUMAR V AP/CSE SECE
  • 21. Programming Style and Documentation • Appropriate Comments • Proper Indentation and Spacing Lines 21ARULKUMAR V AP/CSE SECE
  • 22. Appropriate Comments Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Include your name, class section, instructor, date, and a brief description at the beginning of the program. 22ARULKUMAR V AP/CSE SECE
  • 23. Proper Indentation and Spacing • Indentation – Indent four spaces. – A consistent spacing style makes programs clear and easy to read, debug, and maintain. • Spacing – Use blank line to separate segments of the code. 23ARULKUMAR V AP/CSE SECE
  • 24. Programming Errors • Syntax Errors – Error in code construction • Runtime Errors – Causes the program to abort • Logic Errors – Produces incorrect result 24ARULKUMAR V AP/CSE SECE
  • 25. Getting Started with GUI Programming Why GUI? Turtle Tkniter 25 GUI is a great pedagogical tool to motivate studetns and stimulate student interests in programming. ARULKUMAR V AP/CSE SECE
  • 26. Getting Started with GUI Programming Why GUI? Turtle Tkniter 26 A simple way to start graphics programming is to use Python built-in Turtle package. Run A Turtule Example ARULKUMAR V AP/CSE SECE
  • 27. Getting Started with GUI Programming Why GUI? Turtle Tkniter 27 Later in the book, we will also introduce Tkinter for developing comprehensive GUI applications. Run A Tkinter Example ARULKUMAR V AP/CSE SECE