DEV Community

roe0478
roe0478

Posted on

Python Building Blocks: Literals, and Variables

Well Happy New Year Everyone!!! Before I continue with what I'm learning I just wanted to give a quick shout out to all the programmers both aspiring and vets. I hope 2023 is prosperous for you all and let's own this year.
Let's own our destiny.
Let's get it done!

We talked about reserved words and syntax errors in my last entry. Today I will share more of my learning on the building blocks of Python.

Fixed values such as numbers, letters, strings; these are what are called "string literals" and they allow us to do things. Without them, we cannot ask Python to do a whole lot. Because we haven't given it anything to work with.

examples of literals:

>>>print(1234)
1234

>>>print(13.9)
13.9

>>>print("Hello World")
Hello World
Enter fullscreen mode Exit fullscreen mode

These literals work hand in hand with variables.

If you recall in my last post, we gave Python instructions speaking in its language.

Variables are very important in Python. I learned that variables are a piece of memory where we as programmers can store data and then use that data at a later time. Using last sessions example:

x = “Python”
print(x)
Enter fullscreen mode Exit fullscreen mode

Speaking in a way that Python can understand, we say hey: take this small piece of computer memory and label it "x" then store the name "Python" into this small piece of memory labeled x. Lastly, print whatever the value of x is.

So we stored some data then used that data at a later time by printing it to the screen.

We as programmers get to choose what we name our variables. The data within that variable can be changed down the line in a later statement as well. We use what is called an assignment operator (=) to "assign" data to a piece of memory. That data can be a number, string, Boolean (True or False) among others.

Example of changing the contents of a variable:

x = “Python”
print(x)
Python

x = "Airplane"
print(x)
Airplane

Enter fullscreen mode Exit fullscreen mode

Our variable called x starts out with the value assignment of "Python" and we printed it to the screen. But then we changed the data inside the x variable to "Airplane" and printed it to the screen. So, it wiped the value of "Python" and reassigned the value of "Airplane" to x. Done and Done!!

There is much more great information to absorb on variables and how they can be used. I will continue to fill you in as I learn. Until next time have a great day/week everyone!

Top comments (0)