top of page

What's your name?

In the last lesson, we saw how to print "Hello, world" and other things. But writing print statements every time may not be the best idea. Why not store our stuff in containers called variables?

For example, writing or printing your name like this:

name = "Pulkit"
print(name)

Python Fundamentals

Python Fundamentals

Watch Now

Congratulations 🎉🎉!

You completed variables!

AI Lab Assistant answer here...

Your question...

Ved (Beta)

Video
Ved

Interactive Coding in Jupyter Notebook

Dynamic Notes

Text

Now, if you wish to assign something else to this name variable, like a friend's name, you can do so. 

name = "Mohan"
print(name)

 

This will print:
Mohan

 

Notice how the same variable stores this new value "Mohan". Python will always use the latest value assigned to a variable. 

 

You can use variables of your choice. More examples:

 

pi = 3.14
x = 10
y = -1

Explanation:
We're assigning 3.14 to a variable called pi. Here, = is not an equality sign in Python; rather, it's used for assigning values from right (3.14) to left (pi). Similarly, we've assigned 10 and -1 to variables x and y respectively. Note: Numbers are not written inside "".

Write a note...

hello

Learn more about the different rules for naming variables here.

How it works?

Remember, Python interpreter reads the code from top to bottom and from left to right.

 

name = "Pulkit"

  • Thus, on line 1, the word "Pulkit" is assigned to a variable called name. Now, "Pulkit" lives inside this new variable name.

  • On the second line, we can use our print statement with the name variable inside the parentheses. Notice that we're not quoting the name inside "" as it is a variable consisting of some value.

Variable Lab

Lab

Results

Let's make some mistakes:


name = "Ram"
print(Name)


You'll get a NameError because the variable name in line two, Name, is not described before. We're using name, but we mistakenly wrote Name. Try now:

Your results will appear below.

Correct Variable Name

Quiz (Pilot, AI-Generated)

Assessment

Select your quiz difficulty level, and enter quiz topic, and your learning choice.

message

The boiling point of water is

option 1

option 2

option 3

option 4

Result

Your learning feedback

Test (Pilot, AI-Monitored)

Select your topic and difficulty level to phase a live written test.

message

Your test question.

Your learning feedback

Credits

My AI Lab is built with the following tools and resources:

  • OpenAI API: Powered Ved, personalised quizzes, and learning feedback.

  • ChatGPT: Utilised for designing and coding the AI Lab functionalities, including adaptive tutoring and lab simulations.

  • See more at Python documentation.

Thank you for learning!

Venus will reply here...

Your question...

VenusMoon Logo

Promoting equitable education for all through the fruitful use of AI.

© 2024-25 by VenusMoon Education | Udyam Registration Number: UDYAM-MP-10-0030480

bottom of page