0

For new line I have used "\n" in my code . But it generates error . The code is -

value1=100 value2=10.10 value3 ="Hello world" print value1+"\n"+value2+"\n"+value3; 
3
  • What is your error ? Commented Jan 27, 2015 at 10:27
  • 1
    You need to cast the int and float types to str in order to concatenate them. It's not to do with the newline character Commented Jan 27, 2015 at 10:28
  • Error is - Traceback (most recent call last): File "C:/Python27/test1.py", line 5, in <module> print value1+"\n"+value2+"\n"+value3 TypeError: unsupported operand type(s) for +: 'int' and 'str' Commented Jan 27, 2015 at 10:29

3 Answers 3

2

value1 and value2 are not strings. you must convert them, print str(value1)+"\n"+str(value2)+"\n"+value3

Sign up to request clarification or add additional context in comments.

Comments

1

Best Program with using pep8 format

value1 = 100 value2 = 10.10 value3 = "Hello world" print "Value1 = %s \nValue2 = %s \nValue3 = %s" % (value1, value2, value3) 

OUTPUT

Value1 = 100

Value2 = 10.1

Value3 = Hello world

Comments

0

In addition to the other answers here, the simplest change you can do is to use the grouping operator by changing all + to ,

print value1,"\n",value2,"\n",value3

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.