The Python interpreter CSE 160 University of Washington Ruth Anderson 1.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

Chapter 8 Improving the User Interface
P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
COMP14 RECITATION 1 by- Bian Wu. Bare Bone Environment MS-DOS Prompt (Command Interpreter) Notepad (editor, c:\autoexec.bat) Jvc (J++ compiler) Jview.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
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.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Visual Basic Chapter 1 Mr. Wangler.
Python Programming Fundamentals
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Introduction to Python
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
The Python interpreter CSE 140 University of Washington Michael Ernst.
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Introduction to Computational Linguistics Programming I.
2. Recording a Macro. Macro Recording Select Record Macro from the Macro file menu and the dialog box opposite will appear Your macro will require a name.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Intro Python: Variables, Indexing, Numbers, Strings.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
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.
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.
Hitchhiker’s Guide to CS Lee Sieger, Tim Cook, Jason Day, Zuozhi Yang.
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
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
Practical Kinetics Exercise 0: Getting Started Objectives: 1.Install Python and IPython Notebook 2.print “Hello World!”
Exploring Spyder: An IDE for scientific computing
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
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!
Dive Into® Visual Basic 2010 Express
Visual Basic.NET Windows Programming
CST 1101 Problem Solving Using Computers
Topic: Iterative Statements – Part 1 -> for loop
Introduction to Programming
Introduction to Programming
The Python interpreter
The Python interpreter
An Introduction to Python
Week 2 Computer Programming Learning Objective:
Python Basics with Jupyter Notebook
Python Crash Course CSC 576: Data Science.
Java Programming with BlueJ Objectives
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
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
Class code for pythonroom.com cchsp2cs
Interactive Programming vs. Stored Programs
The Python interpreter
Introduction to Python
Presentation transcript:

The Python interpreter CSE 160 University of Washington Ruth Anderson 1

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 2

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) 3

How to launch the Python interpreter Two ways to launch the interpreter: – Run Canopy; in the window labeled “Python” you should see: “Welcome to Canopy's interactive data-analysis environment!” This window is a Python interpreter called the ipython shell* – Type python or ipython 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 4 * The ipython shell is what is shown in Canopy. You can access either the python shell or the ipython shell from the operating system command line. The ipython shell has more features than the python shell, but both are Python interpreters.

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 Canopy: press the green triangle/play button Hit Control and the letter R at the same time Select the menu item “Run >> Run File” – Type at operating system command line: python myprogram.py 5

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 6

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 a side effect, its value is None 7