Reading Python#

  • This notebooks goal is not to produce python code, but an introduction on to to make sense of (read) code.

    • we will go through and learn some Python terminology and structure.

Python has a syntax… ….and it builds on what happened immediately before, line by line. So the value of y depends on what happened just before.

Open Jupyter Lab
x = 0 + 1   # Python creates x and stores 1 in it
y = x + 1   # Python uses the value of x (which is 1) to compute y = 2

Reading Left to Right and Right to Left

Human thinking → left to right. Left to right: You read the line of code like a sentence: x = 0 + 1 means “x equals 0 plus 1.”

Computer execution → right side first, then assign left. Right to left: Python evaluates the right side first (0 + 1), and then stores that result into the variable on the left (x).

  • References

Introduction to Cultural Analytics & Python, Designed by Melanie Walsh


Attribution Creative Commons CC BY License

READING PYTHON: a program of commands for talking to your computer Created by Dr Heather Froehlich used under Creative Commons CC BY License