A little command line
- the terminal: opening it and reading it
- how spaces are used to separate arguments
- change directories:
cd
- list directory contents:
ls
- directory shortcuts:
~
,.
and..
- where am I? print working directory:
pwd
- make and remove files:
touch
andrm
- make and remove directories:
mkdir
andrmdir
- running python: interactive mode (REPL) vs. executing a .py file
Python Basics
- ints/floats
- math operations:
+
,-
,*
,/
,**
,%
- strings
- errors are good: line numbers, understanding them
- variables and assignment
- builtins:
print
,input
- equality operators:
==
,!=
,>
,<
,>=
,<=
- booleans:
True
,False
- Using
and
andor
- if statements:
if
,elif
,else
Discussion: formatting and style. Snake case. The importance of indentation and how it's different from other languages. PEP 8. A Foolish Consistency is the Hobgoblin of Little Minds.
Using input
, if
statements, and print
, write a program that asks a
question and reacts to the response. Then, let your neighbor try your program.
Recap and stuff we missed
- moving files: the
mv
command - the DRY principle
- making things more robust
More Python
- functions:
def
keyword, positional arguments, keyword arguments,return
- data structures: lists, tuples
- looping:
for
with lists andrange
- list operations: list indexes,
len
,append
,pop
- using the
import
statement - using
random
withrandint
andchoice
Package managers and virtual environments
- extending functionality with packages
- first package: pip, the better package manager
- second package: virtualenv
- using virtual environments to isolate projects
- activating the virtual environment with
source venv/bin/activate
- deactivating with
deactivate
- our first fun package: Pillow for image manipulation
Playing with images in programs
- the
import
statement from [package] import [class or function]
- the
Image
class - the
dir
function - getting the image with
Image.open
- saving an image to a new format with
Image.save
- getting image size with
Image.size
- resizing with
Image.resize
- messing with pixels
getpixel
andputpixel