Posted on

Learn Python Episode #13: Variables

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

Enroll in The Complete Python Course on Udemy!
https://www.udemy.com/python-complete/?couponCode=PYTHONWP

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.

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.

Web – https://josephdelgadillo.com/
Subscribe – https://goo.gl/tkaGgy
Follow for Updates – https://steemit.com/@jo3potato