Using Variables

In the last post, we saw how to print Hello World using the print() command.

Now suppose you want to print your name with Hello World.
Sounds interesting.

But for that, you have to save your name at some location, that is where variables are used.

Lets see an example :


As you can see,

'anyname' is a variable used to take input from user.
The input() command is used to take input from user.

The user inputs his/her name and it is stored in 'anyname'

Next is printing the name.

So, in print() command, you can see 

print("Hello World! This is", anyname)

'Hello World! This is' is written within inverted commas but not 'anyname'
This is because 'anyname' is a variable that contains certain value inside it but the rest of it is a string.

When the program is run, the output is

Hello World! This is <name entered by user>

Comments

Popular posts from this blog

Comparing Python 2.x and Python 3.x

Syntax of Python

IDLE