Home > Backend Development > Python Tutorial > Variables Part-04

Variables Part-04

WBOY
Release: 2024-08-28 18:31:01
Original
532 people have browsed it

Variables Part-04

Suppose you drink tea. No, no tea. Eat coffee. Being a programmer, you can have coffee. It will not be wrong to call coffee as a friend of programmers.

Whatever. What do you need to make coffee now? Hot water, sugar, and coffee. And if the person is too big then you can add milk. I am a poor man.

First heat the water and take coffee from the coffee pot and sugar from the sugar pot. If you need milk, take it from the milk container. Then mix and drink.

Now I have a question for you.

  • You could have bought as much sugar as you wanted from the shop. So why did you take sugar from your pre-stored sugar container?
  • Does the same for coffee and milk but why?

You might say, for my benefit. If you want to know a little detail, your answer can be like this, "I need these things every day, so instead of going to the store again and again, I will bring them all at once and keep them and use them as needed."

But why?

“It will save both my time and energy”

The story is done, let's go to the main point,

The

variable is like the sugar container above, where you can store the various data you need. And like sugar can be used in different places as needed.

See the code below:

variable_name = value
Copy after login

Don't understand anything? Not even to understand. Chinta ki kai baat nahi, me hu na.

To declare a variable in Python, first a valid name of the variable, then the = sign and a value should be placed after the = sign.

Now, let's declare a variable to hold the sugar in your sugar container:

Suppose you keep 100 grams of sugar. Sugar is very expensive.

sugarBox = 100
Copy after login

Here sugarBox is the variable name and 100 is the value.

Now the question may arise in your mind, what is my benefit with variable?

The profit is definitely there. But I am writing pure Bengali. But don't think of anything else.

If you want, you can easily access the value of the variable using its name. Look at the code below:

sugarBox = 100
print(sugarBox)
Copy after login

If you run the above code, the output will be as below.

100
Copy after login

You can use this variable as many times as you want.

as below:

sugarBox = 100
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
print(sugarBox)
Copy after login

Output

100
100
100
100
100
100
100
100
100
100
100
Copy after login

আপনি তো প্রোগ্রামার হয়ে গেছেন। এবার তো আপনি বড় লোক হয়ে যাবেন। এখন কি আপনার ১০০ গ্রাম চিনিতে হবে?

সেই জন্য আপনি আরো ২০০ গ্রাম চিনি নিয়ে আসলেন এবং চিনির পাত্রে রেখে দিলেন তাহলে মোট চিনিত কত গ্রাম হল? ৩০০ গ্রাম।

এবার আপনি কোডের সব কিছু ঠিক রেখে 100 এর স্থানে 300 বসিয়ে দেন। output লক্ষ্য করেন। কিহ? সময় কি save হল?

যাই আজকে এই পর্যন্ত যদি বুঝতে অসুবিধা হয় তাহলে এক কাপ নিয়ে আবার পড়তে বসুন। কফি বানানোর রেসিপি তো উপরে দেওয়াই আছে। এরপরও যদি বুঝতে না পারেন তাহলে অবশ্যই জানাবেন।

বিঃদ্রঃ উপরে অনেক কথা বার্তা সিরিয়াস মনে হতে পারে। দয়া করে সিরিয়াসলি নিবেন না। সব কিছু মজা করার জন্য লিখেছি।

The above is the detailed content of Variables Part-04. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template