Once upon a code-time, in a world not far from our keyboards, there was a school for young programmers called Pythonopolis. Every student there learned how to use magic symbols called โ€œOperatorsโ€. These werenโ€™t wands or potions โ€” no! These were symbols that gave instructions to computers.

Each type of operator had a special job to do, and today, youโ€™re about to meet them one by one!


๐Ÿท๏ธ 1. The Assignment Spell: =

Letโ€™s start with young Ada, a clever coder in Pythonopolis.

One day, she picked up a magic chalk and wrote on her scroll:

age = 8

The scroll glowed! Ada had used the assignment operator =, which is like saying: โ€œI give the name age to the value 8.โ€

Itโ€™s like saying: โ€œHey, computer! From now on, if I say age, I mean 8.โ€

She could also copy that magic and give it to another scroll:

another_age = age

Now both scrolls knew the same secret number!


โž•โž–โœ–๏ธโž— 2. The Arithmetic Spells

Next, Ada visited the Math Room, where all the arithmetic operators danced around.

  • + was the cheerful one who always added things together.
  • - was moody and liked to take away things.
  • * loved to multiply things.
  • / liked to divide things equally.

Ada wrote:

cookies = 5 + 3

Boom! cookies now had the value 8. Then she tried:

juice = 10 - 4  # juice is 6
cakes = 2 * 3   # cakes is 6
shares = 8 / 2  # shares is 4.0

But there were even more powerful spells:

  • % gave her the leftovers: 7 % 3 gave 1 (3 goes into 7 twice, with 1 left).
  • ** was a power spell: 2 ** 3 meant 2 ร— 2 ร— 2 = 8.
  • // was for only the whole part: 7 // 2 gave 3, not 3.5.

She could also say:

score = 10
score += 2  # now score is 12!

The chalk sparkled with delight!


๐Ÿ” 3. The Comparison Scrolls

One morning, Ada tried comparing scrolls.

She used the comparison operators to ask True or False questions.

5 == 5  # True
5 != 3  # True
5 > 3   # True
2 < 1   # False
3 >= 3  # True
2 <= 1  # False

It was like asking, โ€œAre these numbers the same? Bigger? Smaller?โ€

If the answer was true, the scroll glowed green. If false, it glowed red.


๐Ÿ”ฎ 4. The Boolean Magic Words

Ada discovered three powerful words in the logic room:

  • not โ€“ the flipper: not True became False.
  • and โ€“ the checker: True and False was False. Only both True meant True!
  • or โ€“ the helper: True or False was True. As long as one thing was true, the spell worked.

Try this:

sunny = True
warm = False

go_outside = sunny and warm  # False
have_fun = sunny or warm     # True

โš™๏ธ 5. Bitwise and Identity Operators

Now, these were for advanced magic students.

  • &, |, ^, ~, <<, >> โ€” These were bitwise tools, used when talking to computers at the bit level (tiny 0s and 1s).
  • is โ€“ asks if two names point to the same magic object.
  • in โ€“ checks if something is inside a group.

Example:

name = "Ada"
print("d" in name)  # True, because "d" is in "Ada"

๐ŸŽ“ Review Time!

Here are some questions to test your operator magic!

1. What will this line of code print?

result = 7 % 3
print(result)

A. 2 B. 1 C. 3 D. 0


2. Which operator would you use to add two numbers?

A. - B. + C. * D. //


3. What will this return?

not (True and False)

A. True B. False C. Error D. None


4. Which operator checks if two values are equal?

A. = B. != C. == D. >=


5. What will this code return?

"e" in "hello"

A. True B. False C. Error D. โ€œYesโ€


<
Previous Post
๐Ÿง ๐Ÿ Python Data Types: Understanding Data Types Like a Pro Kid Coder!
>
Next Post
๐Ÿงต๐Ÿ“ฆ Python Strings: The Stringy Tale of Roger the Dog ๐Ÿถ