I&C SCI 33 Lecture 1: [Review I]

4 Pages
Unlock Document

Information and Computer Science
I&C SCI 33
Richard Pattis

Lecture 1 [Review I]  Tuesday, April 4, 2017  4:57 PM  Python in Four Sentences:  1. Names (in namespaces) are bound to objects.  2. Everything that Python computes with is an object.     (examples are instance/data, function, module, and class objects)  3. Every object has its own namespace.     (a dictionary that binds its internal names to other objects)  4. Python has rules about how things work.    Objects are the fundamental unit with which Python computes.   • int, module, function, and class objects; each have their own way to compute    Binding  • The process of making a name refer to a value: e.g., x = 1 binds the name x to  the value 1  • In Python, every data instance, module, function, and class is an object that  has a dictionary that stores its namespace: all its internal bindings.  • Diagrams: the name of the variable is in a box, the object value is in an oval  ○ http://www.ics.uci.edu/~pattis/ICS-21/lectures/arrays1d/images/intarray.gif (the syntax of the assignment is for Java, but it's a similar concept)  ○ http://files.software-carpentry.org/training-course/2013/05/Python-variables.png (no ovals, but again, similar concept)    Statements vs. Expressions  • Statements - executed to cause an effect   ○ e.g., binding/rebinding a name or  producing output, control structures  ○ x= 1, y = ['a', 'b', 'c']   • Expressions - evaluated to compute a result   ○ e.g.,  computing some formula, numeric, string, boolean, etc.  ○ 5*x, y.remove('b')    None  • A value (object/instance) of NoneType  • A Python function that terminates without executing a return statement automatically returns the value None    Pass  • Means "do nothing"   • We might use pass as a placeholder until we write the actual statement we  need    Importing: 5 Forms  "import module-name" form:      1. import module­name{,module­name}  a. Bind each module-name to the object representing that imported  module-name.    2. import module­name [as alt­name] {,module­name [as alt­name]}  a. Bind each alt-name to the object representing its preceding  imported module-name.     "from module-name import" form:    3. from module­name import attr­name{,attr­name}  a. Bind each  attr-name to the object bound to that attr-name in module-name.    4. from module­name import attr­name [as alt­name] {,attr­name [as alt­name]}  a. Bind each  alt-name to the object bound to the preceding attr-name in module-name    5. from module­name import *  a. Bind each name that is bound in module-name to the same object it is bound to  in module-name.    Directly iterating over values in a list vs. Using a range to iterate over indexes of values in a list  alist = [5, 2, 3, 1, 4, 0]  for i in range(len(alist)):   print(alist[i])    vs.    for x in alist:  print(x)    • Depending on whether or not you want to keep track of the list indices      Arguments and Parameters (and Binding): Terminology  • DEFINE: Whenever we DEFINE a function (and define methods in classes), we specify the  names of its parameters in its header (in parentheses, separated by commas).  • CALL: Whenever we CALL a function we specify the values of its arguments (also in  parentheses, separated by commas).   • ****It is important that you understand the distinction between the technical term  PARAM
More Less

Related notes for I&C SCI 33

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.