Now, we're going to talk a little bit about Python.
Python is a programming language.
Python is a way that we communicate.
Now Python wasn't invented by computers.
We invented Python as humans as a way to encapsulate our instructions.
And there's lots of different programming languages.
Python, Javascript, C++, tons of them.
Python's just one of them that we happen to teach in this class.
Now, I'll start with a little Harry Potter reference.
Parseltongue is the language of serpents and those who converse with them.
An individual who can speak Parseltongue is known as a Parselmouth.
And it's a very uncommon skill, and it may be even hereditary.
Nearly all known Parselmouths are descended from Salazar Slytherin.
There's our Harry Potter reference.
Python is the language of the Python
interpreter, and those who can converse with it.
We're going to converse with the inside of a computer pretty soon.
An individual who can speak Python is known as a Pythonista.
It is an uncommon skill and may be hereditary.
It may not be hereditary too.
Nearly all known Pythonistas use software initially developed by Guido van Rossum.
Guido van Rossum, this guy right here.
Yo Guido, what's up?
Let's put a mustache on, yo Guido.
Sorry.
I should be nice to him.
He is the inventor of Python.
Python's over 20 years old.
He invented it to make it an easy language but was both easy and powerful.
And that's why it's a great language to start your learning with.
It's a powerful language but it's also designed to be easy to use.
Can anyone guess what the reason for the Python language name is?
[BLANK_AUDIO]
So let's see.
[MUSIC]
Python was named after a famous British comedy show that was in the 60s and 70s
and 80s, I think, named Monty Python, Monty Python's Flying Circus.
And so
And I, I think he was trying to capture a
playfulness, a certain kind of silly fun aspect of Python.
And and so there we go, enough of that.
We done?
Yeah, okay, the music's done now, thank heaven for that.
Okay, so again this is a language and this Guido, he made it for us, he made choices.
He said we're going to put a colon here.
I think we should like indent this and do these things.
And he, he's made choices.
And [COUGH] and some languages have people like some different better than others.
It's kind of an artistic choice.
And, and I like to kind of equate this to
learning a language to speak with people, with humans, you know.
You know, when we're a baby we don't know how to talk and
we start babbling, blah, blah, blah, blah, blah, blah. Maybe we just start crying.
That's the first thing that we do.
[SOUND] But we're like, we're like on this strange
planet. We got to talk to this thing.
So we have to learn its language.
And we're not going to learn it right away.
You don't go like, hey study all night and you know this language.
There's no way you can do that.
Although Rosetta Stone might be a good way to
teach programming, maybe I should take some of their ideas.
So, the thing that's different about learning a
human language versus learning a programming language is that
when we're learning a human language we're talking to
a human, and they're going to do correction for us.
So if
if I say a word incorrectly, like," Mama-alah."
Right?
I don't know.
That was pretty dumb.
Someone listening says, oh, I know what he said, I know what he said.
But Python and computers aren't really listening.
They're kind of dumb.
They can't really correct our mistakes for us
because they don't know what we're trying to say, they really don't.
They're very literal.
And, so it is really common
in the beginning to get upset.
Because we say something we think is cute, and it says, syntax error.
And we'd be like, okay let me try this.
And it says, syntax error.
And so we get this notion, and I had this problem when I was
first programming, I was like, I would like, here's my program, do you like it?
It would say, syntax error.
Now, the problem is, they could reword the messages to be a little nicer
perhaps, but the syntax error isn't really a
judgment on you that says you're a failure.
The syntax error is really saying, I, I don't know what you're saying.
I'm confused.
I only know a few things, and what you just said is not something I understand.
So instead of thinking of the program, the Python as some kind of
evil, demonic monster that just hates you and just keeps saying syntax error,
think of Python more like a dog.
Right, the dog's, what can you talk to a dog?
Can you say "lovely sunset we're having" to a dog?
Because the dog's not going to understand that.
The dog does understand some things like food,
back, walk.
But it doesn't understand the accumulated works of Shakespeare.
So when you talk to a dog, you've gotta be careful
to talk the subset of the vocabulary that the dog knows.
And so this is a key thing when you're first learning.
There's only a certain set of things that Python understands.
It turns out it's easier to teach you Python
than to teach Python to listen to whatever you have to say.
Things like Google make it seem intelligent.
So you can kind of type anything into Google, right?
Well, yeah, billions of dollars later
Google, for at least, like, short things, can
seem like it knows what you're talking about.
In terms of programming, it's a lot easier for you to
figure out the exact precise way to say it, rather than make
it so that we have to spend a billion dollars on
something like Python to figure out what you mean in your programs.
So, let's start talking to Python.
We're talking to Python.
So.
If you've installed Python properly, whether it's on a
Mac or a Windows or on a Raspberry Pi, at
some point you'll be in a terminal program and
you'll type Python to make Python run in interactive mode.
You might have to type c:\ something something Python in Windows.
But at some point you're running Python.
Now Python itself is a program, it's a program
that is asking you to type the Python language.
Now the interesting thing is you've got this chevron prompt
here, and it's kind of another version of "what's next?"
I told you that this hardware was designed
to always want the next instruction to come in.
Well.
Python, once we start it, it really has no idea what to do.
It is, is waiting for you to tell it what to do.
Okay?
So, let me see if I can pop something up here.
So here we go.
Clear that.
And now I'm going to type.
Get this a little closer.
I'm going to start Python, so it's the
operating system now is asking me what next,
I'm saying, oh the thing I want to do next is I want to run Python.
So, here we are, we're sitting in
the Python interpreter and it's asking "what next?"
Okay?
Now, I, it's like I just landed on a, on like a
planet.
And it's, like,
take me to your leader.
Take me to your leader.
That's what you always say when you land on a
planet and are confronted by some kind of a robot.
And it says,
Syntax error.
Remember, it's a dog.
It should just say aarf, right?
Could say, take me to your leader, woof, okay?
Are you friendly?
I don't even spell, think I spelled friendly right.
Syntax error.
Are you dumb?
Syntax error.
Pretty dumb.
I hate computers!
[BLANK_AUDIO]
Syntax error.
It doesn't seem to have a sense of humor.
Try this.
Knock knock.
No sense of humor.
So here's the problem.
It wants us, it's
It doesn't hate us.
It, it just wants to know what we want done.
So, we need to know the Python language.
Luckily, I know a bit of Python.
So I'm going to say, hmm, hey Python, I'm going to want some data.
I want to make a variable named "x".
Just a little place in your memory.
Go find it.
Go find one of your spare places in memory.
And I want you to put 100 in that.
Okay?
Do that.
Now, it's happy because I know the language.
Bonjour.
That we know the language.
Now I want to, but it's saying, "what next?"
So we have to put a program in.
So, let's see.
I'm going to say, hey, Python.
I'm going to make a variable called "y", another area in your memory labeled y,
and I want you to go back and remember that x I gave you before?
Go get that one back and add 50 to that.
And put that in y.
So now I've got something in x and I've got something in y, and let's print y out.
What's in y?
Go look in y where you put that and let's print it out.
150.
So.
We're doing simple things, and actually most
programming is a series of simple things.
The number of statements, different statements
you can do is is relatively few.
So we are talking to Python.
Let's run back to the slides, there we go.
And so.
We give it a series of commands and you
can do the same thing sitting on your computer.
And [SOUND] you type exit or quit with
parentheses to get out of it when you're done.
And that ends the interactive session.
Now this is interactive Python where it's asking us command by command and
then interpreting or running those commands as
we run the command, as we finish.
So.
There'll be, you'll be doing it in some kind of a window.
There's a different way to do it on Windows.
My install documentation on pythonlearn.com gives you
all of this, tells you everything to do.
So now we're basically talking to Python.
So, what language?
I gotta still teach you this language.
So, what do we say when we get ahold of Python, what kinds of things?
Just like any language, a human language, there's like vocabulary,
there's basic words, there's variables and reserved words in Python.
Then we kind of combine those in lines to make
sentence-like structures that themselves are not a full story.
And then we kind of make a story out of it.
Now, the story is in the Python language, not sort of English or
French or a human language, but it still is kind of a
a sequence of small pieces that build to make
bigger pieces that then build to make a whole program.
So here is, again, that same program, right? That same program
of how to count the most common word in a file.
And I mentioned before that it starts by opening the file.
It reads the data from the file.
Splits it into words, counts them all up and
then finds the biggest one and then prints it out.
So "name" is like a word, "equals" is another word, "raw" is a
word, all these things are words, each of these things is like a sentence.
There are blocks of stuff that are kind of paragraphs.
There's kind of a paragraph, paragraph.
I for sure, different color here.
Here's like a paragraph, and a paragraph, and a
paragraph, and then at the end of the day, once you
kind of understand it, and you will understand this before
it's all over, this is kind of like a story.
Right?
It holds together, it has a beginning, a middle, and an end.
Again.
Don't worry about the detail, we've got plenty of chapters to cover this detail.
Don't worry about this particular program.
I'm just sort of getting into the sense that, you'll get it.
But we'll start simple.
So, the first thing that you gotta know how to
do in Python is know what not to do.
Or when you use these reserved words, they have very special meaning to Python.
It's like when you say, "I don't think you're going to get any food today" to a
dog, the dog hears the word "food" and nothing
else. So food is a reserved word for dogs.
Walk, bath, there are other reserved words.
So, what it really means is you can't use
these for anything other than what they mean to Python.
So, print tells it to print things.
Return is used in functions.
Else, if, these are words that if Python sees the word if, it's like,
this means something.
Don't use it for any other purpose except its stated purpose.
We'll learn what those are.
Now if we talk about sentences.
Sentences are kind of, in Python, like a line that kind of have pieces to them.
So here is three pieces of code.
One is x equals 2.
That says, take and find me a piece of memory.
In your RAM.
Allocate it, label it x, and stick 2 in it.
This is kind of like a move 2 into x.
Then this says go get x, add 2 to it, and then put the sum back into x.
Again, little sentences that are kind of like subject predicate, right?
Especially this assignment, it's kind of just, and then print.
Print's a reserved word.
Was one of the was on the list in
the previous slide. And then go read that variable.
So, these are like three sentences in our new little language.