πŸ–₯️
Berkeley CS61A: Notes
  • 🌍Hello, World!
  • πŸ’­Learn to Think Like Your Computer
  • Building Blocks
    • ❗Expressions in Python
      • ℹ️Mathematical Statements
      • 🀫Variables
      • πŸ‘Data Types in Python
    • 🚧Introduction to Functions
      • πŸƒβ€β™€οΈHow Python Executes a Function Call
      • 🚱Functions that Don't Return Anything
    • 🌊Control Flow
      • ⁉️What is an if statement?
      • πŸ’ΎWhat is a Loop?
      • 🚨What are Logical Operators?
        • πŸ˜–Logical Operators, Seemingly Illogical Behavior
      • 🚰How Does Control Flow?
    • ⚑Higher-Order Functions
      • ⏸️What are Higher-Order Functions Used For?
      • πŸ‘†Self-Reference
    • πŸ‘ΎEnvironments and Scope
      • πŸ–ŠοΈHow to Make Environment Diagrams
  • STRUCTURES OF DATA
    • ➰Recursion
      • πŸ«€Anatomy of Recursion
      • β›½Recursive Leap of Faith
    • πŸŽ„Tree Recursion
      • ⬇️The Use It/Lose It Principle
    • πŸ“€Iterables
      • βœ‚οΈList Slicing
      • πŸ’€Deep Lists
      • πŸŒ‹Iterable Functions
      • πŸ’½List Comprehensions
    • πŸ™ˆAbstraction
    • Trees
    • Linked Lists
    • Iterators and Generators
    • Efficiency
  • Extra Topics
    • 🎭Errors and their Types
      • 🏹Error vs Exception
      • πŸ”™What is Backtracing?
    • 🚑How the Terminal and the File are Different
    • 🍬Decorators
  • Debugging Tools
    • πŸ–¨οΈDebugging with Print Statements
    • πŸ›Debugging with the Debugger
Powered by GitBook
On this page

Was this helpful?

  1. Building Blocks

Expressions in Python

The smallest possible.

If you were to imagine Python to be a universe of its own, an expression would be the atom of this universe. An expression is the atomic unit of expression in Python.

So, What is an Expression?

Expressions are representations of value in Python. Something like the expression 1+2 represents the value 3 in Python. Expressions are some combination of values, variables, operators, and function calls. Play around in the Python terminal with me, if you'd like to try a few expressions:

>>> 1 + 2
3
>>> 1 - 2
-1
>>> 1/2
0.5

These are different from statements. Statements are a collections of expressions that together "do something". Expressions can be statements, but statements can't be expressions, if that makes any sense. Here's a few examples:

>>> a = 3
>>> a
3
>>> a + 7
4

>>> def f(x): 
...    return x
>>> f(3)
3

Some of this syntax may not make sense to you β€”Β that's okay! Sometimes, a block of these statements do something unique and we wish them special names β€”Β like if statements, loops or functions. But the big idea to take away here is that everything in Python is a collection of expressions and statements.

PreviousLearn to Think Like Your ComputerNextMathematical Statements

Last updated 3 years ago

Was this helpful?

❗