Learn Python Episode #13: Variables

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 state strings they are not reusable. If I were to simply write "This is a string," 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.

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

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.

Get The Learn to Code Course Bundle!
https://josephdelgadillo.com/product/learn-to-code-course-bundle/

Best,
Joseph Delgadillo
Web: https://josephdelgadillo.com/
YouTube: https://www.youtube.com/c/JosephDelgadillo
Steemit: https://steemit.com/@jo3potato

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center