Learn Python Episode #13: Variables

preview_player
Показать описание

In this video we are going to cover variables in Python, and as you may have guessed, a variable is an object that is variable in nature. So, why do we use variables in our code? Well, when we explicitly write strings they are not reusable. If I were to simply write "This is a sting," I would be unable to reuse that line of code later on in my script. So, one reason we use variables is for re-usability. Another reason we use variables is for passing values into functions, but we will get into that in a later video. The nice thing about Python is that we don't need to declare or define the type of variable. Creating a variable is as simple as this:

greeting = "hello world"

When you hit enter in your terminal or command prompt, Python will not output a response. However, when we call our new variable, Python will print out "hello world"

print(greeting)

Now that the greeting variable is stored in memory, we can make changes to it.

If we print(greeting) now it will returns hello. We can write the following to return hello nick:

print(greeting + " Nick")

In the next video we're going to be talking about some of the built-in functions available to you in Python.

Рекомендации по теме
Комментарии
Автор

Aren't 'typed' languages actually called 'static'? And Python a 'dynamic' one?

jager
Автор

greeting = greeting.split(" ")[1]

this line is not working ??

zmax
Автор

Hey I know this is for newbies but try to cover 3, 4, 5 topics in one video before the newb in question gets bored and jumps off a bridge :)
Make tic tac toe or something easy... variables are taught in math, so the differences between variables in math and programming can't be explained without showing how values are affected in inner and outer scopes, and explaining how the computer stores state, etc.

KingHerring