CSE : Python Programming
|
|
- Eric Atkinson
- 5 years ago
- Views:
Transcription
1 CSE : Python Programming Lecture 2: Data, Classes, and Modules January 22,
2 Administrative things
3 Teaching assistant Brian Summa seas.upenn.edu) Office hours in Moore 100A (Linux lab) Thursday 6 7pm Friday 5:30 6:30pm He'll be doing a lot of the grading on homeworks Talk to Brian S. first if you have a question about grading If that doesn't work out, talk to me next Feel free to ask him questions, as well as me 3
4 Other announcements Homework 2 was due this morning Homework plans: Homework 3 (Othello board) out by tomorrow Homework 4 (Othello AI) out by next week Both will be due two weeks from today My office hours: Wednesday 11 noon, 4:30 6pm 4
5 cse39904submit You must submit all of your files every single time you use cse39904submit to turn in something You cannot submit things in bits and pieces cse39904submit -i hwx will list the files you have submitted for hwx cse39904submit -h tells you how to use it 5
6 Quick poll Would you rather there be a bulletin board for discussions, as in CSE 1xx, or would you rather use the list? I'm going to insist that all discussions happen on exactly one of these things 6
7 The view from here
8 So far in this course One lecture: Crash-course introduction to Python Basic datatypes Basic control flow How to run Python programs Two homeworks, which threw you in the ocean and asked you to swim (not so kind of me to do that ) 8
9 The plan from here Next 3 lectures: Talk about Python itself Everyone here comes from a wide range of backgrounds That leaves 9 lectures to talk about Python itself some more Various Python libraries Somewhere in here, you'll start working on projects Not sure what exactly will happen to homeworks Lectures will continue 9
10 Data in Python
11 What is a variable? All data in Python is represented by objects Then variables must all be references to objects That is, the memory a variable takes up is merely a pointer to some other part of memory that actually has the object We usually think of the thing being pointed to as the value of the variable, not the pointer itself 11
12 >>> q = [2, 3] >>> p = [1, q, 4] >>> print p [1, [2, 3], 4] >>> q[0] = 42 >>> print q [42, 3] >>> print p [1, [42, 3], 4] q The integers should also be pointers, but they're immutable, so it doesn't really matter. 2 3
13 >>> q = [2, 3] >>> p = [1, q, 4] >>> print p [1, [2, 3], 4] >>> q[0] = 42 >>> print q [42, 3] >>> print p [1, [42, 3], 4] p 1 4 q 2 3
14 >>> q = [2, 3] >>> p = [1, q, 4] >>> print p [1, [2, 3], 4] >>> q[0] = 42 >>> print q [42, 3] >>> print p [1, [42, 3], 4] p 1 4 q 42 3
15 p >>> q = [2, 3] >>> p = (1, q, 4) >>> print p (1, [2, 3], 4) >>> q[0] = 42 >>> print q [42, 3] >>> print p (1, [42, 3], 4) >>> p[2] = (... error messages...) TypeError: 'tuple' object does not support item assignment q Notice what it means for a tuple to be immutable!
16 Classes: The basics
17 Object-oriented programming (OOP) Based on the survey results, it seems safe to assume that everyone here knows what OOP is Terminology like the following should be familiar: Class Inheritance Subclass / superclass Instances / objects Methods (instance and static) Instance variables Derived class / Base class 17
18 Some differences from Java Everything in a class is public No overloading Use optional arguments Don't confuse this with overriding Derived classes may have multiple base classes This is known as "multiple inheritance" You should avoid this when possible No super 18
19 Aside: New-style versus Classic-style Basic idea: there should be no distinction between built-in types and user-defined classes I'll try to highlight some of the differences between the two styles of classes It's unlikely you'll come out today with any real appreciation of what makes them different Just be aware that Python is in the process of transitioning to the new-style classes 19
20 Basic structure of a class definition class Derived(Base1, Base2): "Documentation string." <statements> Defines a class Derived which inherits from base classes Base1 and Base2 Derived will be a new-style class if it inherits from a new-style class and classic-style otherwise 20
21 Basic structure of a class definition class Derived(Base1, Base2): "Documentation string." <statements> You can specify no base classes, in which case you get a classic-style class You can specify the base class object if you want a new-style class that inherits as little as possible 21
22 Constructors class Pair(): def init (self, i, j): self.fst = i self.snd = j >>> a = Pair(2, 3) >>> print a < main.pair instance at 0x67300> 22
23 Constructors class Pair(): def init (self, i, j): self.fst = i self.snd = j like Java, but no new needed >>> a = Pair(2, 3) >>> print a < main.pair instance at 0x67300> 22
24 Constructors class Pair(): def init (self, i, j): self.fst = i self.snd = j the constructor of a class is called init >>> a = Pair(2, 3) >>> print a < main.pair instance at 0x67300> 22
25 Constructors class Pair(): def init (self, i, j): self.fst = i self.snd = j Did you notice that init takes 3 arguments, but we constructed an instance by only giving 2? And no optional arguments either! >>> a = Pair(2, 3) >>> print a < main.pair instance at 0x67300> 22
26 Self The first argument of the constructor or a method in a class is usually called self It corresponds to this in Java Since Python has no variable declarations, you need an explicit means of assigning to instance variables self provides you means of doing exactly that It also lets you call methods on the current instance 23
27 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(): return fst The assignments here assign to two variables fst and snd which are local to init Calling get_first() would result in an error 24
28 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(): return fst >>> a = Pair(2, 3) >>> a.get_first() (... error messages...) TypeError: get_first() takes no arguments (1 given) 25
29 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(): return fst method invocation uses familiar dot notation >>> a = Pair(2, 3) >>> a.get_first() (... error messages...) TypeError: get_first() takes no arguments (1 given) 25
30 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(): return fst no self argument >>> a = Pair(2, 3) >>> a.get_first() (... error messages...) TypeError: get_first() takes no arguments (1 given) namely, the instance 25
31 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(self): return fst >>> a = Pair(2, 3) >>> a.get_first() (... error messages...) NameError: global name 'fst' is not defined 26
32 Self (continued) class Pair(): def init (self, i, j): fst = i snd = j def get_first(self): return fst should assign these via self should get this from self >>> a = Pair(2, 3) >>> a.get_first() (... error messages...) NameError: global name 'fst' is not defined 26
33 Self (continued) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst >>> a = Pair(2, 3) >>> a.get_first() 2 >>> a.fst 2 27
34 Self (continued) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst everything is public >>> a = Pair(2, 3) >>> a.get_first() 2 >>> a.fst 2 27
35 Basic rules of thumb Instance variables are referred to through self For example: self.foo Methods and constructors must take at least one argument, which is called self 28
36 Basic rules of thumb Instance variables are referred to through self For example: self.foo Methods and constructors must take at least one argument, which is called self Technically, you can call it anything you want. The convention is to call it self. Also ignoring static methods (for now). 28
37 instanceof instanceof(obj, cls) Return True if obj is an instance of cls Returns False otherwise Works pretty much as you might expect 29
38 Single inheritance Works much as it did in Java Catch #1: Super class constructor is not called automatically (call it yourself if need be) Catch #2: No super in Python Use BaseClass.foo to refer to superclass attributes If you call super class methods like this, you have to pass in self yourself! 30
39 Single inheritance (example) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst class SillyPair(Pair): def get_first(self): return Pair.get_first(self) + 50 def get_second(self): return self.get_first() + self.snd >>> a = SillyPair(2, 3) >>> a.get_second() 55 >>> a.get_first() 52 31
40 Single inheritance (example) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst class SillyPair(Pair): def get_first(self): return Pair.get_first(self) + 50 def get_second(self): return self.get_first() + self.snd >>> a = SillyPair(2, 3) >>> a.get_second() 55 >>> a.get_first() 52 constructor inherited, just like any other method 31
41 Single inheritance (example) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst call the superclass's version class SillyPair(Pair): def get_first(self): return Pair.get_first(self) + 50 def get_second(self): return self.get_first() + self.snd >>> a = SillyPair(2, 3) >>> a.get_second() 55 >>> a.get_first() 52 31
42 Single inheritance (example) class Pair(): def init (self, i, j): self.fst = i self.snd = j def get_first(self): return self.fst call a method on the current instance class SillyPair(Pair): def get_first(self): return Pair.get_first(self) + 50 def get_second(self): return self.get_first() + self.snd >>> a = SillyPair(2, 3) >>> a.get_second() 55 >>> a.get_first() 52 31
43 Modules: The basics
44 What is a module? Basic problems in programming Python: Typing things into the interpreter repeatedly gets old You want to reuse code that someone else has written Modules provide a basic way of organizing code A module mod is simply a Python file mod.py, i.e., "module" is just another name for a Python file 33
45 Loading modules import foo will import the module foo, which should be in the file foo.py What import foo does: If foo has already been imported, do nothing Otherwise, search for the file foo.py in the search path By default, the search path includes the current working directory and the standard library directories For now, put your modules in the current directory 34
46 Loading modules import foo will import the module foo, which should be in the file foo.py What import foo does: If foo has already been imported, do nothing Otherwise, search for the file foo.py in the search path Parse foo.py, raise an exception if there is a syntax error Otherwise, add foo to the list of imported modules The interpreter keeps track of all imported modules 35
47 Loading modules import foo will import the module foo, which should be in the file foo.py What import foo does: If foo has already been imported, do nothing Otherwise, search for the file foo.py in the search path Parse foo.py, raise an exception if there is a syntax error Otherwise, add foo to the list of imported modules Execute the code in foo.py 36
48 "Executing" a module About that last step: what does it mean? Each loaded module has a symbol table which contains entries for every name it defines Each statement is executed, and if necessary, an entry is added to the symbol table 37
49 Saving some typing from mod import foo, bar, baz Lets you use foo, bar, baz without typing "mod." from mod import * Lets you use anything from mod without typing "mod." 38
50 Saving some typing from mod import foo, bar, baz Lets you use foo, bar, baz without typing "mod." from mod import * Lets you use anything from mod without typing "mod." a lie, but it's good enough for now 38
51 Saving some typing from mod import foo, bar, baz Lets you use foo, bar, baz without typing "mod." from mod import * Lets you use anything from mod without typing "mod." >>> import sys >>> sys.stdout.write("hello!\n") Hello! >>> sys.modules {'copy_reg': <module 'copy_reg' from... 38
52 Saving some typing from mod import foo, bar, baz Lets you use foo, bar, baz without typing "mod." from mod import * Lets you use anything from mod without typing "mod." >>> from sys import stdout >>> stdout.write("hello!\n") Hello! >>> modules (... error messages...) NameError: name 'modules' is not defined 39
53 Saving some typing from mod import foo, bar, baz Lets you use foo, bar, baz without typing "mod." from mod import * Lets you use anything from mod without typing "mod." >>> from sys import * >>> stdout.write("hello!\n") Hello! >>> modules {'copy_reg': <module 'copy_reg' from... 40
54 Saving some typing The from forms of import don't define the module name! >>> from sys import * >>> sys.stdout.write("hello!\n") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'sys' is not defined 41
55 Tips about importing modules Python evaluates the contents of a module only the first time it's imported Avoid from mod import * when possible It clutters the namespace It becomes difficult to determine who defined what 42
56 Modules as programs Many tools for Python import modules so that they can analyze them Therefore, it is a bad idea if non-trivial code gets executed when a module is imported For example: def foo(): return 42 print "Hello!" not a good idea 43
57 Modules as programs If you're "running" a file bar.py as a program, then in that case, bar. name will be ' main '. bar.py def foo(): return 42 if name == " main ": print "Hello!" >>> import bar >>> bar. name 'bar' 44
58 Modules as programs If you're "running" a file bar.py as a program, then in that case, bar. name will be ' main '. bar.py def foo(): return 42 if name == " main ": print "Hello!" prompt$ python bar.py Hello! 45
59 Next time More on classes Scoping and namespaces in Python Times after that: Review some basic datatypes and constructs Exceptions Generators (?) Iterators (?) 46
CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern
CSE 399-004: Python Programming Lecture 12: Decorators April 9, 200 http://www.seas.upenn.edu/~cse39904/ Announcements Projects (code and documentation) are due: April 20, 200 at pm There will be informal
More informationCSE : Python Programming. Packages (Tutorial, Section 6.4) Announcements. Today. Packages: Concretely. Packages: Overview
Announcements CSE 399-004: Python Programming Lecture 07: Packages, Command-line arguments, and Unit testing February 26, 2007 http://www.seas.upenn.edu/~cse39904/ No homework this week There may be one
More informationCSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria
CSE 399-004: Python Programming Lecture 5: Course project and Exceptions February 12, 2007 Announcements Still working on grading Homeworks 3 and 4 (and 2 ) Homework 5 will be out by tomorrow morning I
More informationCSE : Python Programming
CSE 399-004: Python Programming Lecture 10: Functional programming, Memoization March 26, 2007 http://www.seas.upenn.edu/~cse39904/ Announcements Should have received email about meeting times Length:
More informationCSE : Python Programming
CSE 399-004: Python Programming Lecture 08: Graphical User Interfaces with wxpython March 12, 2005 http://www.seas.upenn.edu/~cse39904/ Plan for today and next time Today: wxpython (part 1) Aside: Arguments
More informationMITOCW MIT6_01SC_rec2_300k.mp4
MITOCW MIT6_01SC_rec2_300k.mp4 KENDRA PUGH: Hi. I'd like to talk to you today about inheritance as a fundamental concept in object oriented programming, its use in Python, and also tips and tricks for
More informationPREPARING FOR PRELIM 2
PREPARING FOR PRELIM 2 CS 1110: FALL 2012 This handout explains what you have to know for the second prelim. There will be a review session with detailed examples to help you study. To prepare for the
More informationA lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.
Handout 2 Functions, Lists, For Loops and Tuples [ ] Functions -- parameters/arguments, "calling" functions, return values, etc. Please make sure you understand this example: def square(x): return x *
More informationCSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Winter 2013 Ruby logistics Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationRuby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework
Ruby logistics CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Autumn 2018 Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationCSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion
CSC 148 Lecture 3 Dynamic Typing, Scoping, and Namespaces Recursion Announcements Python Ramp Up Session Monday June 1st, 1 5pm. BA3195 This will be a more detailed introduction to the Python language
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationENVIRONMENT MODEL: FUNCTIONS, DATA 18
ENVIRONMENT MODEL: FUNCTIONS, DATA 18 COMPUTER SCIENCE 61A Jon Kotker and Tom Magrino July 18, 2012 1 Motivation Yesterday, we introduced the environment model of computation as an alternative to the earlier
More informationA PROGRAM IS A SEQUENCE of instructions that a computer can execute to
A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form
More informationLecture 18. Classes and Types
Lecture 18 Classes and Types Announcements for Today Reading Today: See reading online Tuesday: See reading online Prelim, Nov 6 th 7:30-9:30 Material up to next class Review posted next week Recursion
More informationLecture 02, Fall 2018 Friday September 7
Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python
More informationFormal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5
Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can
More informationCS 11 python track: lecture 4
CS 11 python track: lecture 4 Today: More odds and ends assertions "print >>" syntax more on argument lists functional programming tools list comprehensions More on exception handling More on object-oriented
More informationWeek - 01 Lecture - 04 Downloading and installing Python
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and
More informationCSE 341, Autumn 2015, Ruby Introduction Summary
CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful
More informationLecture 3: Recursion; Structural Induction
15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion
More informationCS 11 python track: lecture 2
CS 11 python track: lecture 2 Today: Odds and ends Introduction to object-oriented programming Exception handling Odds and ends List slice notation Multiline strings Docstrings List slices (1) a = [1,
More informationSupporting Class / C++ Lecture Notes
Goal Supporting Class / C++ Lecture Notes You started with an understanding of how to write Java programs. This course is about explaining the path from Java to executing programs. We proceeded in a mostly
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationCS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.
CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationLecture 2. Object Orientation 1 / 51
Lecture 2 Object Orientation 1 / 51 Homework 1 Homework 1 was due at noon You will be graded on: Correctness: 15 points (passing all RSpec tests) Style: 5 points (having no Rubocop style offenses) Best
More informationPython for C programmers
Python for C programmers The basics of Python are fairly simple to learn, if you already know how another structured language (like C) works. So we will walk through these basics here. This is only intended
More informationA function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).
CIT Intro to Computer Systems Lecture # (//) Functions As you probably know from your other programming courses, a key part of any modern programming language is the ability to create separate functions
More informationCSE341: Programming Languages Lecture 20 Arrays and Such, Blocks and Procs, Inheritance and Overriding. Dan Grossman Spring 2017
CSE341: Programming Languages Lecture 20 Arrays and Such, Blocks and Procs, Inheritance and Overriding Dan Grossman Spring 2017 This lecture Three mostly separate topics Flexible arrays, ranges, and hashes
More information61A Lecture 3. Friday, September 5
61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework
More informationEXPRESSIONS, STATEMENTS, AND FUNCTIONS 1
EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1 COMPUTER SCIENCE 61A June 24, 2014 0.1 Warmup What Would Python Do? >>> x = 6 >>> def square(x):... return x * x >>> square(x) >>> max(pow(2, 3), square(-5)) -
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationCONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction
CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want
More informationCSE 113 A. Announcements - Lab
CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure
More informationLecture 3. Functions & Modules
Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should
More informationLecture 2. Object Orientation
Lecture 2 Object Orientation 1 Homework 0 Grades Homework 0 grades were returned earlier this week Any questions? 2 Homework 1 Homework 1 is due tonight at 11:59pm You will be graded on: Correctness: 15
More informationNote: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.
Com S 227 Fall 2017 Miniassignment 1 50 points Due Date: Monday, October 16, 11:59 pm (midnight) Late deadline (25% penalty): Tuesday, October 17, 11:59 pm General information This assignment is to be
More informationLecture 8. Conditionals & Control Flow
Lecture 8 Conditionals & Control Flow Announcements For This Lecture Readings Sections 5.1-5.7 today Chapter 4 for Tuesday Assignment 2 Posted Today Written assignment Do while revising A1 Assignment 1
More informationMITOCW watch?v=kz7jjltq9r4
MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection
More informationLecture 2. Object Orientation 1 / 50
Lecture 2 Object Orientation 1 / 50 Homework 1 Homework 1 was due last night You will be graded on: Correctness: 15 points (passing all RSpec tests) Style: 5 points (having no Rubocop style offenses) Best
More informationCS61A Lecture 20 Object Oriented Programming: Implementation. Jom Magrotker UC Berkeley EECS July 23, 2012
CS61A Lecture 20 Object Oriented Programming: Implementation Jom Magrotker UC Berkeley EECS July 23, 2012 COMPUTER SCIENCE IN THE NEWS http://www.theengineer.co.uk/sectors/electronics/news/researchers
More informationLecture 21. Programming with Subclasses
Lecture 21 Programming with Subclasses Announcements for Today Reading Today: See reading online Tuesday: Chapter 7 Prelim, Nov 10 th 7:30-9:00 Material up to Today Review has been posted Recursion + Loops
More informationLecture 21. Programming with Subclasses
Lecture 21 Programming with Subclasses Announcements for This Lecture Assignments Prelim 2 A4 is now graded Mean: 90.4 Median: 93 Std Dev: 10.6 Mean: 9 hrs Median: 8 hrs Std Dev: 4.1 hrs A5 is also graded
More informationIntro. Classes & Inheritance
Intro Functions are useful, but they're not always intuitive. Today we're going to learn about a different way of programming, where instead of functions we will deal primarily with objects. This school
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationThe Stack, Free Store, and Global Namespace
Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information
More informationA Crash Course in Python Part II. Presented by Cuauhtémoc Carbajal ITESM CEM
A Crash Course in Python Part II Presented by Cuauhtémoc Carbajal ITESM CEM 1 Importing and Modules 2 Importing and Modules Use classes & functions defined in another file A Python module is a file with
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is
More informationLecture 3. Functions & Modules
Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should
More informationThe Java Type System (continued)
Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass
More informationLecture 5. Defining Functions
Lecture 5 Defining Functions Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember the survey Readings Sections 3.5 3.3 today Also 6.-6.4 See online readings
More informationCS Homework 11 p. 1. CS Homework 11
CS 111 - Homework 11 p. 1 Deadline 11:59 pm on Friday, December 12, 2014 How to submit Each time you would like to submit your work: CS 111 - Homework 11 IF they are not already on nrs-labs, then transfer/save
More informationPREPARING FOR PRELIM 1
PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,
More informationDEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A
DEBUGGING TIPS COMPUTER SCIENCE 61A 1 Introduction Every time a function is called, Python creates what is called a stack frame for that specific function to hold local variables and other information.
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationSixth lecture; classes, objects, reference operator.
Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours
More informationObject Model Comparisons
Object Model Comparisons 1 Languages are designed, just like programs Someone decides what the language is for Someone decides what features it's going to have Can't really understand a language until
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationPython: common syntax
Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable
More informationLecture 21. Programming with Subclasses
Lecture 21 Programming with Subclasses Announcements for Today Reading Today: See reading online Tuesday: Chapter 7 Prelim, Nov 9 th 7:30-9:00 Material up to Today Review has been posted Recursion + Loops
More informationBIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett cduckett@cascadia.edu Lecture 3 Announcements By now everyone should be up and running with Java, jgrasp, and the Becker Robots
More informationGenome Sciences 373: Genome Informatics. Quiz section #1 March 29, 2018
Genome Sciences 373: Genome Informatics Quiz section #1 March 29, 2018 About me Email: hpliner@uw.edu Office hours: Thursday right after quiz section (2:20pm) Foege S110 Or by appointment Other help: I
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationFormal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5
Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 [talking head] This lecture we study theory design and implementation. Programmers have two roles to play here. In one role, they
More informationMITOCW watch?v=flgjisf3l78
MITOCW watch?v=flgjisf3l78 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To
More informationLists, loops and decisions
Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence
More informationProgramming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras
Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Module 12B Lecture - 41 Brief introduction to C++ Hello, welcome
More informationCSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209
CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System
More informationAl al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department
Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department 0901212 Python Programming 1 st Semester 2014/2015 Course Catalog This course introduces
More informationCS162 Week 1. Kyle Dewey. Friday, January 10, 14
CS162 Week 1 Kyle Dewey Overview Basic Introduction CS Accounts Scala survival guide Office Hour Choose an hour from within: Tuesday/Thursday 11 AM - 1 PM Friday 11 AM - 4 PM Also available by appointment
More informationLecture 4. Defining Functions
Lecture 4 Defining Functions Academic Integrity Quiz Reading quiz about the course AI policy Go to http://www.cs.cornell.edu/courses/cs11110/ Click Academic Integrity in side bar Read and take quiz in
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
More informationPython 1: Intro! Max Dougherty Andrew Schmitt
Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and
More informationIntroduction to Python Code Quality
Introduction to Python Code Quality Clarity and readability are important (easter egg: type import this at the Python prompt), as well as extensibility, meaning code that can be easily enhanced and extended.
More informationClass extension and. Exception handling. Genome 559
Class extension and Exception handling Genome 559 Review - classes 1) Class constructors - class MyClass: def init (self, arg1, arg2): self.var1 = arg1 self.var2 = arg2 foo = MyClass('student', 'teacher')
More informationAbout Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python
About Python Python course is a great introduction to both fundamental programming concepts and the Python programming language. By the end, you'll be familiar with Python syntax and you'll be able to
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 12 February 7, 2018 Partiality, Sequencing, Records Chapters 12, 13 Midterm 1 This Friday in class Review session Tonight, 6 7:30 PM DRLB A1 Announcements
More informationCSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures
CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught
More informationCIT 590 Homework 5 HTML Resumes
CIT 590 Homework 5 HTML Resumes Purposes of this assignment Reading from and writing to files Scraping information from a text file Basic HTML usage General problem specification A website is made up of
More informationBe careful when deciding whether to represent data as integers or floats, and be sure that you consider all possible behaviors in computation.
Table of Contents: 1. Integers and floats 2. for vs. while loops 3. Checking boolean conditions with if/else 4. Docstrings 5. Changing collections while iterating over them 6. Directly Accessing Instance
More informationSmalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)
A Bit of History Some notable examples of early object-oriented languages and systems: Sketchpad (Ivan Sutherland s 1963 PhD dissertation) was the first system to use classes and instances (although Sketchpad
More informationCS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion
CS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion Assorted Scheme Basics 1. The ( is the most important character in Scheme. If you have coded in other languages such as C or Java,
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationLogistics. Final Exam on Friday at 3pm in CHEM 102
Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create
More informationPREPARING FOR THE FINAL EXAM
PREPARING FOR THE FINAL EXAM CS 1110: FALL 2017 This handout explains what you have to know for the final exam. Most of the exam will include topics from the previous two prelims. We have uploaded the
More informationCS1110 Lab 1 (Jan 27-28, 2015)
CS1110 Lab 1 (Jan 27-28, 2015) First Name: Last Name: NetID: Completing this lab assignment is very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness
More informationGIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes
GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and
More informationEXPRESSIONS, STATEMENTS, AND FUNCTIONS 1
EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1 COMPUTER SCIENCE 61A September 4, 2013 0.1 Warmup What Would Python Do? >>> x = 6 >>> def square(x):... return x * x >>> square(x) >>> max(pow(2, 3), square(-5))
More informationLecture 1. Basic Ruby 1 / 61
Lecture 1 Basic Ruby 1 / 61 What does this do? 3.times do print 'Hello, world!' end 2 / 61 Why Ruby? Optimized for programmer happiness Used for Ruby on Rails Very popular web framework 3 / 61 Course Policies
More informationPracticum 5 Maps and Closures
Practicum 5 Maps and Closures Assignment Details Assigned: February 18 th 2014. Due: February 20 th, 2014 at midnight. Background One of the requirements of PA1 Part 2 using a data structure to hold function
More informationThe following content is provided under a Creative Commons license. Your support
MITOCW Recitation 2 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make
More informationClasses and Objects 1
Classes and Objects 1 Built-in objects You are already familiar with several kinds of objects: strings, lists, sets, tuples, and dictionaries An object has two aspects: Some fields (or instance variables)
More informationClass extension and. Exception handling. Genome 559
Class extension and Exception handling Genome 559 Review - classes 1) Class constructors - class myclass: def init (self, arg1, arg2): self.var1 = arg1 self.var2 = arg2 foo = myclass('student', 'teacher')
More informationCOMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012
COMPUTER SCIENCE IN THE NEWS CS6A Lecture 2 Scheme Jom Magrotker UC Berkeley EECS July 24, 202 http://spectrum.ieee.org/tech talk/robotics/artificial intelligence/a texas hold em tournament for ais 2 TODAY
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationIntroduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python
More information