We want to thank the many people that have made this workshop possible.
First, the generosity of our sponsors have provided facilities for the workshop, food and refreshments, and travel assistance for our guest speakers. Please give a hand to our fabulous sponsors:
We are committed to offering a positive and productive workshop for you. We are proud to be an OpenHatch (@openhatch) affiliated event. OpenHatch is a non-profit that helps people become contributors to free and open source software. OpenHatch is a friendly community and can help you find a suitable project if you are interested in contributing.
While we are thanking the PSF and OpenHatch, I would like to thank Jessica McKellar, PSF Director and OpenHatch board member (@jessicamckellar), for sharing her materials from her Intro to Python workshop as well as providing encouragement and support to us.
If anyone wishes to tweet their appreciation, please do so.
A programming community outreach workshop, brought to you by the generous volunteers and leadership from:
Thanks to David and Kendall of SDPUG, Juliet of PyLadies SD, and John of Inland Empire Python for their support.
Introduction of who is here to teach and help you today.
Please take a moment to share 2-4 sentences about yourself.
We are all volunteers. If you enjoy this workshop and decide to continue with Python programming, we encourage you to volunteer at the next Intro to Python Workshop.
We are also very thankful that you have chosen to spend the better part of your Saturday sharing Python with us. It's a language that we have fun using to make all sorts of projects and a thoughtful, accepting, considerate, and fun community that we are glad to take part in.
And now...let's get going with some Python development!
You should have completed the Python 3.4 setup instructions on your own: http://nbviewer.ipython.org/github/pythonsd/intro-to-python/blob/master/part-0.ipynb
If not, please do it now.
Tried but ran into errors? Raise your hand or place a yellow sticky note on your screen to show that you need help. A volunteer will come over to help you.
Don't be shy. Setup problems are common. It's particularly important for everyone who's stuck to get help right now before we move on, to ensure that you get the most out of this workshop.
Volunteers will be walking around to check everyone's setup. Have your setup checked.
When a volunteer comes over, open up a command prompt and type this, to show that you are ready:
$ python3 --version
Python 3.4.1
Once you've had your setup checked:
After completing these steps, you should:
From your command prompt, type python3
to enter IDLE.
Some regular math operations.
2 + 2
4
1.4 + 2.25
3.65
4 - 2
2
2 * 3
6
4 / 2
2
0.5/2
0.25
Special type of division (floor)
3 // 2
15.5 // 2
Horizontal line spacing does not matter in Python in an individual statement. In a multiline program it does, you typically indent 4 spaces.
2 + 2
2+2
Parens and order of operations follow typical mathematics conventions in Python. _
in IPython signifies the previous result.
(1 + 3) * 4
x = 4
x * 3
_ + 8
A trip to PyCon
jeans = 5
shoes = 2
socks = 12
shirts = 1
items_packed = jeans + shoes + socks + shirts
items_packed
print(items_packed)
Using type() to find the datatype
Let's use a function. You'll be hearing more about functions later today. For now let's say that a function is like a Personal Assistant. You ask for a job to be done, and if you give the assistant the correct instructions, he will do the tasks asked.
One handy thing that our Python Personal Assistant, aka Funky Function, can do is tell us a variable's current data type.
type(shirts)
type(0.99)
Questions?
String data type
"Hello"
"Python, I'm your #1 fan!"
type("Hello")
Concatenating strings
name = "Carol"
2 + 2
"Carol" + "Willing"
"Carol " + "Willing"
"Carol" + " " + "Willing"
name = "Carol"
"My name is " + name
Tip - arrow up to save time 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'
Quotes (single, double, triple)
"Python, I'm your #1 fan!"
"A" * 40
h = "Happy"
b = "Birthday"
(h + b) * 10
Displaying versus printing in IPython
"Hello"
print("Hello")
Questions? Quick review
3 ** 3
type(1)
type(1.0)
type("1")
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")
Exiting the interpreter is a good thing to know.
To exit, type exit()
or press CNTL-D.
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)