The Python interpreter

Slides:



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

Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
 Recap – Python Basics. Python  Python is an interpreter which reads and executes a python script.  A python script is a text file, which contains.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Lecture 1 The Basics (Review of Familiar Topics).
Chapter 2 Writing Simple Programs
Functions and abstraction Michael Ernst UW CSE 190p Summer 2012.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
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.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
The Python interpreter CSE 140 University of Washington Michael Ernst.
Introduction to Computational Linguistics Programming I.
Testing Michael Ernst CSE 140 University of Washington.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
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.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
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.
COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
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.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
The Python interpreter CSE 160 University of Washington Ruth Anderson 1.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Chapter 15. Modules Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Functions with Arguments and Return Values, Oh My! CS303E: Elements of Computers and Programming.
PYTHON PROGRAMMING LANGUAGE.
Chapter 2 Writing Simple Programs
G. Pullaiah College of Engineering and Technology
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 9 Repetition.
Python Loops and Iteration
The Python interpreter
Think What will be the output?
Topics Introduction to Repetition Structures
1 Python Lab #1 Intro to Python Adriane Huber Debbie Bartlett.
CS190/295 Programming in Python for Life Sciences: Lecture 1
Chapter 5 Repetition.
Conditions and Ifs BIS1523 – Lecture 8.
Chapter 9 Control Structures.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The Python interpreter
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
slides created by Marty Stepp
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
Lists in Python Outputting lists.
5. Functions Rocky K. C. Chang 30 October 2018
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Python Basics with Jupyter Notebook
Relational Operators.
Introduction to Computer Science
CSE 190p University of Washington Michael Ernst
CISC101 Reminders Assignment 3 due today.
CMPE 152: Compiler Design April 18 – 30 Labs
The Python interpreter
EN Software Carpentry Python – A Crash Course Esoteric Sections Compiled Languages.
Interactive Programming vs. Stored Programs
The Python interpreter
Control 9 / 25 / 19.
Presentation transcript:

The Python interpreter CSE 190p University of Washington Michael Ernst

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

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 function 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

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