DEV Community

Cover image for Python Day Four : Simple and practical 🤔
Amina
Amina

Posted on

Python Day Four : Simple and practical 🤔

Day Four lesson : Variables in Python

Variables are used to store data that can be used later in a program.
Example:

X= "Musa"
Y= 20
print(X)
print(Y)
Enter fullscreen mode Exit fullscreen mode

Explanation

  • X = "Musa" stores the name Musa in variable X.
  • Y = 20 stores the number 20 in variable Y.
  • print(X) displays the value of X.
  • print(Y) displays the value of Y. Output:
Musa
20
Enter fullscreen mode Exit fullscreen mode

String Variable in Python

A string variable stores text or words. Text must be written inside quotation marks (" ").
Example:

name = "Musa"
print(name)
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • name is the variable.
  • "Musa" is the text stored in the variable.
  • print(name) displays the stored text. Output:
Musa
Enter fullscreen mode Exit fullscreen mode

Integer Variable in Python

An integer variable stores whole numbers (numbers without decimal points).

Example:

birthday= 2025
print(birthday)
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • birthday is the variable name.
  • 2025 is a whole number (integer).
  • print(birthday) displays the value stored in the variable. Output:
2025
Enter fullscreen mode Exit fullscreen mode

Variables are the building blocks of programming. By learning how to store and use data, you are taking an important step toward creating real applications. Keep practicing and trust the learning process! 💻🐍

Top comments (0)