DEV Community

Cover image for Python3 Programming - Exercise 1 - Variables
Michael Otu
Michael Otu

Posted on • Edited on

2

Python3 Programming - Exercise 1 - Variables

Creating a variable

A variable is a placeholder ( a name, a label, a tag) given to an address ( a memory location) of a value in memory.
You can think of a variable as a box, which has a name. This box will have a value. Whenever we reference ( call) this variable ( name of the address), we then get the value stored at that address.
To create a variable and assign it a value, all we have to think about is an equation.
Eg: x = 2 . x is the variable ( the placeholder) that points to the address of the value, 2. So 2 is the value. A single ( one) equal-to sign, =, is known as the assignment operator. It takes what is on the right ( the value) and assigns ( puts) it into what is on the left ( the variable).
In Python, the data type of a value is controlled dynamically ( meaning as the program runs) so we don't have to worry about it ( memory management).

More examples:

variable assignment

All these are examples of variable assignment ( variable creation) of different data types.

Rules

  • variable names can start with a letter or an underscore
  • followed by a letter, an underscore or a number
  • a variable name can not begin with a number or dot or special symbols (+, -, /, *, and others)
  • a variable name can not have white-space characters (space, newline, tab, and others)

Practicals

  • Create ten variables and assign them any values suitable ( perhaps, as above).

Summary:

  • Variable represents the name given to the memory address.
  • Calling the variable returns the value
  • The value stored in a variable can change anytime - that's why we call it a variable
  • To create a variable, think about an equation, LHS = RHS. LSH is the variable_name, RHS is the value. Eg: full name = "John Doe"

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

Debugging and Monitoring Basics for Builders

What is monitoring, and why does it matter for your hackathon project? In this kickoff session, we’ll cover the basics of debugging and introduce you to tools like Sentry that help you catch issues early. Learn how to make your app more stable, secure, and future-proof—so it’s not just ready for submission, but ready for whatever comes next.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️