Skip to main content
Skip to content

Lesson 2 of 12

Variables with rakho and constants with pakka

Give values a name with rakho, change them later, and lock the ones that must never change with pakka.

7 min

A variable is a labelled box

rakho means "keep". rakho naam = "Asha"; keeps the text Asha in a box labelled naam. Later you can use the label instead of the value. Names may contain letters, digits and underscores, but cannot start with a digit — kul_marks and marks2 are fine, 2marks is not.

Expected output

Press Run to try it

Asha rehti hai Pune mein

Changing a value

Once a variable exists, give it a new value with = alone — no rakho the second time. Writing rakho again for the same name in the same block is an error, because the box already exists.

You can use a variable's own value on the right-hand side: score = score + 10; reads the old score, adds ten and stores the result back.

Expected output

Press Run to try it

Shuru: 50Bonus ke baad: 60

pakka: values that must not change

pakka means "fixed" or "for sure". A value declared with pakka cannot be reassigned — if you try, the program stops with a runtime error that names the constant. Use it for things like tax rates, the number of days in a week, or a game's maximum lives.

If you declare a variable without a value, as in rakho jawab;, it starts as khali (empty).

Expected output

Press Run to try it

Din: 7Jawab abhi: khali

Where a variable lives

Every pair of curly braces { } creates a new block. A variable made with rakho inside a block exists only inside it. Code outside the block can still read and change variables that were declared outside, which is how a loop updates a running total.

Expected output

Press Run to try it

Total: 5

Practice exercise

Create a variable daam with value 120 and a constant GST with value 18. Make daam the price including GST using daam = daam + daam * GST / 100; and print Final daam: 141.6.

Expected output

Final daam: 141.6
Open in playground
Show solution
solution.altf
rakho daam = 120;
pakka GST = 18;
daam = daam + daam * GST / 100;
bol("Final daam:", daam);