2

Is it possible to produce the following somehow?

name = raw_input("Enter name: ")
age = raw_input("Hello %s, please enter your age") %name

I know I can substitute a + to concatenate the strings, but I was curious if this would work somehow.

Simplex
  • 35
  • 1
  • 6

2 Answers2

3

Just put the variable inside parentheses

age = raw_input("Hello %s, please enter your age" % name) 
vaultah
  • 40,483
  • 12
  • 109
  • 137
3

You should do it using the newer python string formatting:

age = raw_input("Hello {0}, please enter your age".format(name))

It gives you many more formatting options. Do read.

Community
  • 1
  • 1
sshashank124
  • 29,826
  • 8
  • 62
  • 75