DEV Community

Wriju's Blog
Wriju's Blog

Posted on

Day 2 - Variables for Text [Python for Students]

You have observed how you can print a simple text into the python window. However, there is a small challenge, if you have to type the same text again and again, you need to either copy and paste it into your print function every time or type. If we can use a small indicator to store the whole text then every time we can just simply use that indicator to print it. It's like a roll number given to a student. When a teacher discusses about student they can mention the roll number instead of calling out the full name or all the features of that individual. That's why we use names for everything. Same happens in programming language, we use a name to store the whole string and that name is often known as variable.

We will see how differently we can use our greetings and print them by their name.

gm = "Good morning"
print(gm)
Enter fullscreen mode Exit fullscreen mode

In Above gm is the variable name which can be used later as well. Every time you don't need to type the whole text. Just use the name wherever needed.

Watch the video

Day 2 - Exercise

  1. Create a variable with a name myname and assign the value of your name. Then call the variable in print() function.
  2. Create a variable for your favourite movie and print() it.
  3. Clear all the output.

Top comments (0)