Here's another programming-language cheatsheet. It's been a couple of years since I've done any Python programming, and now I'm taking the online CS373: Programming a Robotic Car course, which uses Python for quizzes and homework assignments, so I have to get back up to speed.
As always, this is the information I've found useful in reacquainting myself with a programming language. It may not help you at all.
Links
Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
if name == 'Foo': | |
foo() | |
elif name == "Bar': | |
bar() | |
else: | |
wtf() | |
numbers = ['one', 'two', 'three'] | |
for x in numbers: | |
do_something(x); | |
for i in range(len(numbers)): | |
do_something(numbers[i]) | |
def a_function(x): | |
print x | |
print [n*3 for n in range(10) if n%2 == 1] # prints "[3, 9, 15, 21, 27]" | |
# create a matrix with five rows and six columns, initialized with zeros | |
matrix_5_by_6 = [[0 for col in range(6)] for row in range(5)] | |
f = open("myfile.txt") | |
for line in f: | |
process(line) | |
import re | |
result = re.match(pattern, string) |