Python Basics

Violet Whitney
Data Mining the City
2 min readSep 3, 2018

--

Processing is a programming language and visual development environment.
Python is a high level programming language commonly used by data scientists. We will run the Python language in Processing. Technically speaking we are actually running a language called“jython” which allows us to write in the same syntax as Python while the language is seamlessly integrated with Java. For more Python help check out the following link:

File Names

Python is a language files end in .py
In the program Processing we will run the Python language. All Processing file names should end in .pyde

Python Code Cheat Sheet

  • Syntax — Python uses indentation to indicate a block of code. This indentation structures the sequence of executing those blocks.
  • Comments are made with a #. Comments are not executable code, they are meant to describe code for the programmer’s reference.
  • Data Types
  • Variables — A variable can have a short name (like x and y) or a more descriptive name (age, carName, total_volume). A variable name can only contain alpha-numeric characters and underscores (A-z, 0–9, and _ ), and are case sensitive (age, Age and AGE are three different variables). They are often written like this in camelCase or CamelCase .
  • local variable are declared inside a function, and can be used only inside that function
  • global variable are declared outside any function, and they can be accessed (used) on any function in the program
  • Operators — perform operations on variables and values
  • List is a collection which is ordered and changeable. Allows duplicate members.
  • Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
  • Set is a collection which is unordered and unindexed. No duplicate members.
  • Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
  • Arrays — store multiple values in one single variable
  • If — math logic that executes if statement meets the condition set
  • Else — math logic that executes if statement doesn’t meet the condition set (catches anything which isn’t caught by the preceding conditions)
  • While Loop — execute a set of statements as long as a condition is true.
  • For Loop — iterate over a sequence (avlist, a tuple, a dictionary, a set, or a string)
  • Functions — block of code which only runs when called, which allows data (parameter) to be passed in and can return a result
  • Classes — an object constructor, or a “blueprint” for creating objects
  • JSON — a structured list

--

--

Violet Whitney
Data Mining the City

Researching Spatial & Embodied Computing @Columbia University, U Penn and U Mich