A Lightning Introduction to Python - Stanford University
[Pages:31]A Lightning Introduction
to Python
Will Monroe CS 109 tutorial 13 April 2017
xkcd comic by Randall Munroe (no relation):
Basic syntax
def fizzbuzz(n): for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: print('fizzbuzz') elif i % 3 == 0: print('fizz') elif i % 5 == 0: print('buzz') else: print(i)
fizzbuzz(100)
Basic syntax
TYPES
def fizzbuzz(n):
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
print('fizzbuzz')
elif i % 3 == 0:
SEMICOLONS
print('fizz')
elif i % 5 == 0:
print('buzz')
else:
print(i)
BRACKETS
fizzbuzz(100)
Whitespace
Whitespace matters in Python! Sometimes.
if i % 3 == 0 and i % 5 == 0: print('fizzbuzz')
elif i % 3 == 0: print('fizz')
elif i % 5 == 0: print('buzz')
else: print(i)
Whitespace
Whitespace matters in Python! Sometimes.
if i % 3 == 0 and i % 5 == 0:
INDENT = "{ }"
print('fizzbuzz')
elif i % 3 == 0:
NEWLINE = "SEMICOLON"
print('fizz')
elif i % 5 == 0:
print('buzz')
else:
print(i)
4 spaces is a common convention.
Don't mix spaces and tabs.
Whitespace
Whitespace on otherwise blank lines is ignored. if i % 3 == 0 and i % 5 == 0:
ARE THERE SPACES HERE? DON'T KNOW, DON'T CARE.
print('fizzbuzz') elif i % 3 == 0:
print('fizz') elif i % 5 == 0:
print('buzz') else:
print(i)
Whitespace
Whitespace is ignored inside all brackets/parens. if (i % 3 == 0 and i % 5 == 0):
print('fizzbuzz') elif i % 3 == 0:
print('fizz') elif i % 5 == 0:
print('buzz') else:
print(i)
Whitespace
Whitespace is ignored inside all brackets/parens.
if (i % 3 == 0 and i % 5 == 0):
print('fizzbuzz') elif i % 3 == 0:
print('fizz') elif i % 5 == 0:
print('buzz') else:
print(i)
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- tries and string matching stanford university
- python cheat sheet programming with mosh
- python cheat sheet
- tsune documentation read the docs
- ond fluent python
- the python hangman game
- strings and pattern matching purdue university
- exploring data using python 3 charles r severance
- python interview questions tutorials point
- cs229 section python tutorial stanford university
Related searches
- stanford university philosophy department
- stanford university plato
- stanford university encyclopedia of philosophy
- stanford university philosophy encyclopedia
- stanford university philosophy
- introduction to python pdf
- stanford university ein number
- introduction to python programming pdf
- stanford university master computer science
- stanford university graduate programs
- stanford university computer science ms
- stanford university phd programs