yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Python | Lesson 1


3m read
·Nov 3, 2024

Processing might take a few minutes. Refresh later.

Hey guys, this is M Kids, and on with Python Lesson One. So this is going to be the first of many Python tutorials that I'm going to be making, in which I will teach you the basics to pretty cool stuff in Python. Not to say that the basics aren't cool.

So the reason I'm doing this specifically with Python is because I made some tutorials on other languages, and people, you know, requested languages; as you know, they want to learn something. So Python was the most requested language, and it's pretty cool. I learned it, and I'm going to teach it to you.

I'm going to be using terminal to code in Python. Terminal is a good environment, in my opinion. If you want to use it, that's all right. If you don't want to use it, then you can use a text editor or something else. But I'm going to be using terminal to program in Python.

So we're going to start out by editing our first Python application. Now, on Unix, there's one liner code before every Python program you want to put, and that is #!/usr/bin/python. That is just for executable stuff. You don't have to understand that; that's really not part of Python itself.

Under this is where all our code actually goes. So let's say we want to make a Hello World application. That's normally the first thing anyone makes in a programming language. So what we're going to do is do print "Hello, World!". So this will print out the text "Hello, World!".

You see, we have print, which is a command. We have left quote "Hello, World!" right quote, and this will print out the text "Hello, World!". So to run this, we type python <space> and then the file name, and it'll say "Hello, World!".

All right, so we've gotten started; we're doing our first Python program. Now, let's say we want to make the user enter their name, and then it'll say hello to them. What we're going to do is say, "Enter name, please." Now, we're going to say name = raw_input(). Now we're going to say print "Hello, " + name.

So what this does, essentially, is print out "Enter name, please," then it creates a variable called name and assigns it whatever they type in. A variable is like in math; something that can change, that's normally represented with something that's not a number.

Now, in math, variables can only be one letter; in programming, they can be any length or, you know, they have a limited length, but you know it can be longer than one letter. So here, we're assigning name to be whatever they type in that happens to be called raw_input, and then this following line prints out "Hello, " + their name + "!".

So you might wonder how does this last line work? The answer to that is that it takes the string "Hello," then it adds onto it name, which is also a string, and adds onto that the string "!". Now, a string is a piece of text; it's a string of characters, essentially, and that's why it's called a string.

So, you're going to be hearing that term as well as int, which stands for integer, which is a whole number a lot in programming in general. So it's good to know those. So if we run this right now, enter name "Alex," and it says "Hello, Alex."

So we've already gotten input from the user; it's pretty impressive, and it only took three lines of code. So let's say now we want to ask them for their age, and based on their age, say something that we think about them.

So we're going to do from there is print "Enter your age, please." We're going to get it in years, so we're going to say age = raw_input(). The thing is, the age is going to be a string; we can't really use it as if it's an integer if it's a string.

So we're going to say n_age, which stands for number age, equals int(age). And what this essentially does is convert the string age to an int. So there's a function called int which, you know, you give it age, and once again, if you've done functional notation in math, you will understand this a bit better.

So we've done this. Now we're going to say if—and this is just like if statements on a programmable calculator, for instance. So it's just comparing things, and it's going to do something based on what we're comparing. So we're checking if...

More Articles

View All
Wading for Change | Short Film Showcase | National Geographic
Foreign [Music] There’s a power in belief my family always used to say. Responder, believing is power. So when I would see magazines of, you know, white fly fishermen in Yellowstone, I did believe that it would be me one day. Leaving home for me has been …
How I Got Arrested Working to Save Elephants | National Geographic
Imagine this: I’m in Tanzania and I am about to enter the airport in Dar es Salaam. I have a large suitcase with elephant tusks inside. I’m trying to put all the bags in together to try to mask, and the bags go through. Then he says the worst thing an air…
2017 Maps of Meaning 10: Genesis and the Buddha
[Music] I told you at the beginning of the class that I started working on this material partly because I was interested in why people were so inclined to go to any lengths to protect their belief systems. I wanted to understand, and I knew that those wer…
Double replacement reactions | Chemistry | Khan Academy
Check this out! I have two clear, colorless solutions over here. Let’s pour them into each other. We pour the first one, and we pour the second one, and boom! We now get a white color solution. Here’s another example: again, two colorless solutions. We p…
Enrique Iglesias - Bailando ft. Descemer Bueno, Gente De Zona
I look at you, and it takes my breath away. When you look at me, my heart skips a beat. My heart slowly beats. In the silence, your look says a thousand words (uh). The night when I’m begging you not to let the sun come up. Dancing (dancing), dancing (da…
See How Ancient Past and Present Meet in This Coastal Town | National Geographic
(soft music) [Gabriel] This is Huanchaco. This is my hometown. Huanchaco is a small fishing village that is north of the city of Trujillo, and it’s a very rich place in archaeological sites. There has been a continuous occupation in this area for more th…