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.

1
  • when if ask you for input -- then just enter %s Commented Apr 21, 2014 at 14:42

2 Answers 2

3

Just put the variable inside parentheses

age = raw_input("Hello %s, please enter your age" % name) 
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

@user3556942, Nope. Python2 as well. And really useful in some cases. Your choice :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.