If you haven't already, please complete the short setup instructions at: http://bit.ly/intro-setup
Please also visit: http://codeacademy.com
and create an account.
After completing these steps, you should:
Raise your hand (or place a yellow sticky note on your screen), if you need help.
Introductions, motivation
Interactive lecture: first steps with Python
Practice
Interactive lecture: lists and loops
Practice
Wrap-up and next steps
Terminal and start python
2 + 2
1.4 + 2.25
4 - 2
2 * 3
4 / 2
1 / 2
Whole number 1 divided by whole number 2
1.0 / 2
2 + 2
2+2
(1 + 3) * 4
x = 4
x * 3
Variables
cups_of_flour = 5
cups_of_flour * .5
1 / 2
1.0 / 2
Two different data types
Let's use a function
type(1)
type(1.0)
Questions?
String data type
"Hello"
"Python, I'm your #1 fan!"
type("Hello")
name = "Carol"
2 + 2
"Carol" + "Willing"
"Carol " + "Willing"
"Carol" + " " + "Willing"
name = "Carol"
"My name is " + name
Tip - arrow up save typing
"Hello" + 1
"Hello" + "1"
type(1)
type("1")
"Hello" + str(1)
len("Hello")
len(name)
"The length of my name is " + str(len(name))
"Hello"
'Hello'
"Python, I'm your #1 fan!"
"A" * 40
h = "Happy"
b = "Birthday"
(h + b) * 10
Printing - interactive vs file
"Hello"
print("Hello")
Questions?
3 ** 3
type(1)
type(1.0)
type("1")
Make choices
True
False
type(True)
type(False)
0 == 0
0 == 1
0 != 1
"a" == "A"
1 > 0
2 >= 3
-1<0
.5 <= 1
"H" in "Hello"
"x" in "Hello"
"a" not in "abcde"
type(True)
type("True")
type(true)
x = 4
x == 4
if 6 > 5:
print("Six is greater than 5")
if 0 > 2:
print("Zero is greater")
if "banana" in "bananarama":
print("I miss the 80s")
One of two actions
sister = 15
brother = 12
if sister > brother:
print("Sister is older")
else:
print("Brother is older")
1 > 0 and 1 < 2
1 < 2 and "x" in "abc"
"a" in "abc" and "b" in "abc" and "c" in "abc"
"a" in "hello" or "e" in "hello"
temp = 32
if temp > 60 and temp < 75:
print("Nice and cozy")
else:
print("Too extreme for me")
One of three things
sister = 15
brother = 15
if sister > brother:
print("Sister is older")
elif sister == brother:
print("Twinsies!!")
else:
print("Brother is older")
Questions? 47 min mark
Practice problems - Codeacademy practice Strings and choices http://bit.ly/py-practice
from IPython.display import YouTubeVideo
# a tutorial about Python at PyCon 2014 in Montreal, Canada by Jessica McKellar
# Credit: William Stein.
YouTubeVideo('MirG-vJOg04')
from IPython.display import IFrame
# Pull in the tutorial prep information from OpenHatch wiki
IFrame('http://bit.ly/intro-setup', width='100%', height=350)