Variables in Python - Definition & Declaration - Python Tutorial for Beginners

preview_player
Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ How to Create a Variable in Python?

More complex programs need a way of labelling data with a name, so it can be referenced later on. This has the rather wonderful side-effect of making computer code easier to read!

Nonetheless, there are certain rules and regulations that you have to follow, while writing a variable. Let's take a look at the variable definition to understand how we declare a variable in Python.

○ Variable Definition

In a programming language, a variable is a memory location. Think of a variable as a name, attached to a particular object. Variables are like containers for storing data values ... The value that you have stored into this container may change in the future, according to the specifications.

○ Create a Variable / Variable Declaration

In Python, variables do not need to be defined or declared in advance, with any particular type - as it is the case in many other programming languages. Thus, variables can even change type after they have been set. A variable in Python is created as soon as a value is assigned to it, and then you can start using it. Its assignment is done with a single equals sign.

n = 300

This is read or interpreted as “n is assigned the value 300.” Once this is done, n can be used in a statement or expression, and its value will be substituted.

print(n)
OUTPUT: 300

Later, if you change the value of n and use it again, its new value will be substituted instead.

n = 1000

print(n)
OUTPUT: 1000

Python also allows multiple assignment, which makes it possible to assign the same value to multiple variables. The chained assignment above assigns 300 to the variables a, b, and c - simultaneously.

a = b = c = 300
print(a, b, c)
OUTPUT: 300 300 300

Let's play this video, stick around and watch until the end of this video! 👍🏻

- Digital Academy™ 🎓

***

☞ WATCH NEXT:

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡

♡ SUPPORT US ♡

***
Рекомендации по теме
Комментарии
Автор

Do you know How to use variables in Python? 🤔

DigitalAcademyOnline