Your first program
Using IDLE or your favorite text editor, type the following
program and save it into a file called hello.py
:
name = raw_input('What\'s your name? ')
print 'Hello', name
print 'It\'s nice to meet you.'
Several interesting things are going on here:
- The
raw_input
function will print a prompt,
wait for the user to type something, and return the resulting
text, which gets assigned to the variable name
.
- There is a single quote
'
in the prompt. We
have to "escape" it using a back-slash.
- The
print
command is followed by a string
literal ('Hello'
) and a variable
(name
). These are separated by commas. They will
be separated by a single space, when printed.