Skip to main content

Variable Declarations

What are Variables? 🧮

Think of variables as magic boxes where you can store data—numbers, words, or even true/false statements! These boxes come with labels (names) so you can find them easily.

In pseudo-code, variables are declared using the DECLARE keyword. Let’s dive into this exciting world of variable declarations and see how to convert them to Python.


Syntax in Pseudo-Code

Here’s how variables are declared in pseudo-code:

DECLARE VariableName : DataType

Examples:

DECLARE Age : INTEGER
DECLARE Name : STRING
DECLARE Temperature : REAL
DECLARE IsStudent : BOOLEAN

Conversion to Python 🐍

In Python, there’s no need to use DECLARE or specify the type of data. You simply assign a value, and Python figures out the type automatically. Amazing, right?

Here’s how the above pseudo-code converts to Python:

Variable Declarations in Python
Age = 0  # INTEGER
Name = "" # STRING
Temperature = 0.0 # REAL
IsStudent = False # BOOLEAN

Supported Data Types

Pseudo-Code Data TypePython EquivalentExample
INTEGERintAge = 16
STRINGstrName = "Alice"
REALfloatTemperature = 36.5
BOOLEANboolIsStudent = True

Pro Tip

In Python, variable names are case-sensitive, so age and Age are different variables. Keep this in mind to avoid sneaky bugs!


Let’s Practice 📝

Try converting these pseudo-code declarations into Python:

Challenge
DECLARE Score : INTEGER
DECLARE Greeting : STRING
DECLARE PiValue : REAL
DECLARE IsRainy : BOOLEAN

Python Solution:

Score = 0
Greeting = ""
PiValue = 0.0
IsRainy = False

Great job! 🎉