Created by Guido van Rossum, a former resident of the Netherlands, whose favorite comedy group at the time was Monty Python's Flying Circus.
python>>>, you know you're in the interpreter
This is how your computer wishes you could speak to it:
Type in "hello". Don't forget the quotes.
You get 'hello' back
Try 'hello'
Try 'How are you?'
Ok, that doesn't make for fun conversations
Enter 2
You get 2 back!
Enter 2+2
Woohoo! We get 4. The Pi is longer just repeating what we say!
Try:
200000000 + 3
or
592387438274 -92837847
Try 4 * 8
Try 9 / 4
Oh oh. What happened here?
Let's try 9.0 /4 or 9/4.0
Try "2"+"2" and compare with 2+2
Try "hello,"+"world"
Try "hello"+2
Try "wow!"*5
A string is a collection of characters one after the other
An integer is a whole number, just like we learnt in Math
Also known as a decimal number
A type is "what it is"
type(2)
type("Hello")
type(3.14159)
What can we do with strings?
We can tie one at the end of the other
firststring+secondstring
"hello,"+"world"
We can repeat a string
but you should never repeat a lie
"I will not lie."*200
try "this is cool".lower()
oops! Try this instead:
"this is cool.".upper()
Or even "this is cool".upper()+"!"*3
Try:
"the lord of the rings".title()"the lord of the rings".capitalize()"the lord of the rings".upper()Try:
dogname = "Fido"
dogname.upper()
You just yelled at your dog!
Try the following:
dogname = "Brutus"
catname = "Felix"
runs = "{} runs after {}"
runs.format(dogname,catname)
Try inversing dogname and catname
Variables are basically boxes that contain something.You can refer to the content of the box by naming the label of the box
x = 4
put 3 in a box labelled y.
y = 3
Take the contents of box x and box y, add them together, and put the result in box z
z = x + y
Show z
z
x = 10
z
The content of z isn't changed when we change the content of x. We have to recalculate z if that's what we need
If you don't remember what you put in a box, you can always type it
x="something I'll soon forget"
type(x)

x = 3 + 1
4 = x + 1
x = x + 1

x = x + 1In computer speak, this means "take the content of box x, add 1 to it, and put it back into box x"
Start IDLE
There's IDLE and IDLE3
two versions of Python: 2.7 and 3.2 (or 3.4)
We will use 2.7
Woah! Here's the >>> prompt again!
Yup. This is another way to access the interpreter. Try it out
We are no longer having a conversation with the interpreter. But we're still not dealing with a translator/compiler either.
We can keep our work on disk, and then send it to the interpreter.
You know the drill, File/New, File/Open, File/Save As.., File/Save
Enter 2+2, save as firstprogram.py, and hit F5
Save under Documents/Python Projects
F5 means Save and Run
nothing at all
Go back to your file, and type print 2+2 and try again with F5
Now we have to tell the interpreter every single thing we want to see.
Otherwise the interpreter stays quiet.
(it did the work though, it's just not telling you)
A function is a piece of code that's already written
It can be called whenever you want
Functions look like this:
function_name(list_of_parameters_separated_by_comma):
Example: len("I like my dog")
pow(2,8)
print is a function, but it's an exception
in Python 3, it's no longer an exception, they fixed it
for now we use: print "I like my dog"
Many functions are defined in libraries
You have to import the library before you can access the function
import math
math.sqrt(16)