The Python interpreter CSE 140 University of Washington Michael Ernst.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
UW CSE 190p Section 6/21, Summer 2012 Dun-Yu Hsiao.
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
How to install the Zelle graphics package
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Recitation 1 Programming for Engineers in Python.
Chapter 1: Python Basics CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Streaming Twitter. Install pycurl library Use a lab computer From the course website Download the links from pycurl and twitter streamer Extract site-packages.zip,
Introduction to Python
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Introduction to Computational Linguistics Programming I.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Python From the book “Think Python”
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
An Introduction to Front-end Web Development Tom Perkins.
Intro Python: Variables, Indexing, Numbers, Strings.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
File I/O Michael Ernst UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Variables, Expressions and Statements
Illustration of a Visual Basic Program Running an Ada Program 1 by Richard Conn 11 September 1999.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
CS2021 Week 2 Off and Running with Python. Two ways to run Python The Python interpreter – You type one expression at a time – The interpreter evaluates.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Random Bits of Perl None of this stuff is worthy of it’s own lecture, but it’s all a bunch of things you should learn to use Perl well.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
The Python interpreter CSE 160 University of Washington Ruth Anderson 1.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Introduction to Programming Python Lab 1: My First Program 8 January PythonLab1 lecture slides.ppt Ping Brennan
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
UW CSE 140 Section 1/10, Winter Find partners! Group can be 2-4 people. Try to share as much as possible about what you think with your teammates!
Fundamentals of Programming I Overview of Programming
CST 1101 Problem Solving Using Computers
Introduction to Programming
Introduction to Programming
The Python interpreter
Introduction to Programming
Week 1 Computer Programming Year 9 – Unit 9.04
The Python interpreter
An Introduction to Python
Learning Outcomes –Lesson 4
Teaching London Computing
Introduction to Programming
Python Lesson’S 1 & 2 Mr. Kalmes.
Python Basics with Jupyter Notebook
Chapter 1: Programming Basics, Python History and Program Components
Input and Output Python3 Beginner #3.
Introduction to Programming
CSE 190p University of Washington Michael Ernst
The Python interpreter
Mu Editor – New User Cheat Sheet – CircuitPython Mode
The Python interpreter
Mu Editor – New User Cheat Sheet – CircuitPython Mode
Interactive Programming vs. Stored Programs
The Python interpreter
Presentation transcript:

The Python interpreter CSE 140 University of Washington Michael Ernst

Two ways to run Python The Python interpreter – You type one expression at a time – The interpreter evaluates the expression and prints its value Running a Python program – Python evaluates all the statements in the file, in order – Python does not print their values (but does execute print statements) Writing an expression outside a statement (assignment, print, etc.) is useless, unless it is a function call that has a side effect

The Python interpreter The interpreter is a loop that does: – Read an expression – Evaluate the expression – Print the result If the result is None, the interpreter does not print it This inconsistency can be confusing! (Jargon: An interpreter is also called a “read- eval-print loop”, or a REPL)

How to launch the Python interpreter Two ways to launch the interpreter: – Run IDLE; the interpreter is called the “Python shell” – Type python at the operating system command line Type exit() to return to the operating system command line These are not the same: Operating system command line, or “shell” or “command prompt” (cmd.exe under Windows) or “terminal” – Runs programs (Python, others), moves around the file system – Does not understand Python code like 1+2 or x = 22 Python interpreter – Executes Python statements and expressions – Does not understand program names like python or cd

Running a Python program Python evaluates each statement one-by-one Python does no extra output, beyond print statements in the program Two ways to run a program: – While editing a program within IDLE, press F5 (menu item “Run >> Run Module”) Must save the program first, if it is modified – Type at operating system command line: python myprogram.py

Python interpreter vs. Python program Running a Python file as a program gives different results from pasting it line-by-line into the interpreter – The interpreter prints more output than the program would In the Python interpreter, evaluating a top-level expression prints its value – Evaluating a sub-expression generally does not print any output – The interpreter does not print a value for an expression that evaluates to None This is primarily code that is executed for side effect: assignments, print statements, calls to “non-fruitful” functions In a Python program, evaluating an expression generally does not print any output

Side effects vs. results Some Python code is executed because it has a useful value (72 – 32) * 5.0 / 9 math.sqrt(3*3 + 4*4) Some Python code is executed because it has a side effect print “hello” x = 22 A function (call) can be of either variety – Think Python calls a function that returns a value a “fruitful function” – A function that only prints some text is non-fruitful – A function should either return a value, or have a side effect It is bad style for a function to do both – Printing a value is completely different from returning it When the code is executed for side effect, its value is None