Skip to main content

Command Palette

Search for a command to run...

Day 2: Variables and Assignments in Python

Exploring Python Basics: A Dive into Variables and Assignments

Updated
2 min read
Day 2: Variables and Assignments in Python
H

A coder how works for excellence...

On the second day of my Python learning adventure, I delve into the fundamentals of variables and assignments. As I navigate through this territory, I'm pleased to discover how smoothly things are progressing. Basic concepts surrounding Python variables have been absorbed, and I'm eager to share my newfound knowledge through illustrative code snippets.

Variables

Variable are the key to access some type of data. It works as lable to a data. We can access our data with the help of their address and that address is stored in a variable. Variables also helps us to call some data with a understandable name. we can make them more intuitive.

name = "Himanshu"
age = 23
address = "Rishikesh"
print("A variable containing my name : ",name)

In the given example if a programmer wants to store a name on a variable then he/she can give a variable name like name or username so another programmer can understand what is stored in that variable.

Assignment operator

Assignments in Python are denoted by the '=' symbol. This operator is used to store data into a variable. For example, to store a user's name into a variable called 'name', we simply write 'name = "User name"'. The '=' operator assigns the value to the variable. It's important to note that the '==' operator, on the other hand, is used for comparison, not assignment. These operators have distinct purposes and use cases.

Note: we can delete a variable with del variable_name

name = "Himanshu"
print("name variable before deleting : ",name)
delete name
print("After deleting the variable : ",name)

I've initialized a variable named 'name' with a specific value. Initially, I print the value stored in 'name'. However, upon executing the command 'del name', I delete the variable itself. Consequently, if an attempt is made to print the 'name' variable thereafter, an error will be raised.

Python

Part 3 of 45

In this series, we're diving deep into Python, covering everything from the fundamental basics to advanced topics.

Up next

Day 3: Operators and Expressions in python

Mastering Operators: Unveiling Expressive Python Syntax

More from this blog

ReactJS Made Easy: Simplifying Frontend Development for Web Applications

89 posts