Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this lesson, we're going to go over some of the basics of writing Python programs.
Part of the reason that I really like Python as a first language is
that it doesn't take much to actually write a simple Python program.
So, when we write a Python program,
we are going to write our Python code in this window,
and the code that we write is going to go into
a Python interpreter which
is a program that's running behind the scenes,
but it takes what we write in
our code window and interprets it and then depending on what write,
it might send something to the output.
So, again this is the source code,
this is the output and the Python Interpreter looks at our source code.
So, we've already seen a Hello World Python program,
but I'm going to write a program that's even simpler.
This is a valid Python program.
So, if I click save and run,
then you aren't going to actually see anything in the output program,
but Python did actually interpret and run this program correctly.
So, remember that there's this hidden python interpreter,
and when we actually ran this code,
the Python interpreter looked at our source code,
ran it and just saw that there was no output for it.
So, when we write code,
we're actually writing what are called expressions.
Learning to program is in part learning
the right expression to write for what we actually want to compute.
So, 100 is an expression,
and when we write expressions,
what the Python interpreter does is it computes the value of those expressions.
So, we have expressions,
every expression has a value.
So, in the case of the expression 100,
the value of the expression 100 is just 100,
and then every value also has what's called a type.
A type is like a category of data.
So, the type of 100 is an integer.
An integer is just a round number.
So, I'm going to add onto this program by writing another expression.
So, here's another expression 3.14.
Again, when I run my program, nothing shows up,
but what's happening is that behind the scenes,
the Python Interpreter is looking at my code and deciding what to output.
So, here we have two expressions,
the first expression is 100,
the second expression is 3.14.
Both of these expressions have a value.
So, the value of 100 is 100.
The value of 3.14 is 3.14 and both of those values have types.
So, the type of 100 is an integer.
The type of 3.14,
because it has a decimal place,
is something called a float,
short for floating point number.
So, we can write expressions that compute all the values that we want.
In Python, we'll do these computations behind the scenes,
again with this Python Interpreter.
But typically, we want our programs to actually give us some feedback.
We want to do something and then give us back some value in the output window.
In other words, we don't just want our source code to go
to the Python Interpreter and get no output,
we usually actually want some output or some feedback from our programs.
In order to do that,
what we need to do is we need to use what are called print statements.
So, a print statement is a special kind
of expression that tells something to show up in our output window.
So, I'm going to modify my source code to say rather than
just computing the value to also print out the value.
The way that I do that is I say, print,
open parentheses and then the value of
whatever expression I want to print out and then close parentheses.
So, if I only say print 100 and I run my program,
then I'll see that in my output window,
I get 100 because I specified that I want to print out the value of this expression.
So, notice here that print 100 prints out 100,
but when I say just the expression 3.14,
then this doesn't lead to any output.
In order to actually print out the value of this expression,
I also would need to add a print statement here.
Now, when I run my code,
then you'll see that the value of both of these expressions is printed.
So far, we have seen two kinds of types.
We've seen integers, which are round numbers like
100 and floats which are decimal point numbers like 3.14.
Another type that we've actually seen in an earlier lecture was a string.
So, when we said, print Hello world,
then this expression Hello world is a string.
A string is a sequence of characters and if I run this program,
then I'll see that Hello world is what actually gets printed out when I run mine too.
So, so far, we've seen the types integers like 100,
strings like Hello world and floats,
it's short for floating point number like 3.14.
In all of these cases, these 100,
the string Hello world or 3.14 are all expressions.
Now, expressions are like the building blocks of programming.
We can combine and reuse expressions to get more and more complicated programs.
So, the expressions that we've written so far are what are called literal expressions,
where the value is the same as the expression itself,
so the value of the expression 100 is 100,
the value of the expression 3.14 is 3.14.
Let's move on to operators to see how we can combine
expressions to get more complicated expressions.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.