



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the basics of python programming, specifically tailored for the cs61a course. It covers essential concepts such as expressions, values, data types (integers, floats, booleans, strings), and operators. The notes also explain call expressions, nested expressions, and the evaluation process in python. Furthermore, the document discusses the use of names and variables, assignment statements, environment diagrams, and functions, including function definitions, parameters, return values, and the concepts of global and local frames. It also touches on name lookup rules, providing a foundational understanding of python programming for beginners.
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




It is pretty simple - get used to your coding environment and a few of the basics of Python. Lab 0 While this is optional, it’s probably best to do it just to get used to the very basics of Python as well as ok.py, the autograder used in CS61A. Basics of Python Expressions + Values Programs work to manipulate values Expressions in programs evaluate to values Values can have different data types (string, float, boolean, integer, etc.) Python evaluates these expressions , and then (potentially) displays its values Data Types Data Type Example Values Integers 2, 44, 25 Floats 3.14, 2.73, 6
Data Type Example Values
Boolean s True, False Strings Hi, ben Operators These are pretty self-explanatory Opera tor Example Expression What it does
For example: x = 2 y = 3 print(x + y) # Returns 5 print(x - y) # Returns - These values can also change: x = 2 print(x)
x = x + 5 print(x)
The equals sign used above is not similar to the one used in mathematics; it is used for assignment rather than equality, which means that you set a value to the variable. This assignment statement works by
complicated than variables due to the local and global frames (more on that later). What is a function?
value = example(3)
print(value)
Frames There are different frames, which you can think of as different rooms in the same house.
that were created in the main body of the program.
variables that can’t be accessed outside the function. For example: unhelpful_name = 0 # variable in the global frame def unhelpful_function(unhelpful_name): # variable in the local frame (even though it has the same name it isn't the same variable) return unhelpful_name # >>> 2
called in the function is the one passed into the function. unhelpful_function(2) Name Lookup Rules Python looks up names in a user-defined function using the following logic: