0

Is it possible to do something like this (using python 3):

le = "\n"
var1 = 2
var2 = 5

print("INFORMATION"+le
      "-----------"+le
      "Variable1: {}".format(var1)+le
      "Variable2: {}".format(var2)+le
      )

3 Answers 3

4

Yes. take a look at docs.

General example:

var1 = 2
var2 = 5
print("INFORMATION", 
      "------------",
      "Variable1: {}".format(var1),
      "Variable2: {}".format(var2), sep='\n')
Sign up to request clarification or add additional context in comments.

Comments

1

You could store this string in an object and then print it:

out = "INFORMATION"+le+"-----------"+le+"Variable1: {}".format(var1)+le+"Variable2: {}".format(var2)+le
print(out)

Or if you want to do it easier you can also do like that:

print("INFORMATION\n-----------\nVariable1: {}\nVariable2: {}\n".format(var1, var2))

Or if it is too long and you want to spare it in different lines in your code:

out = "Information\n" /
      "-----------\n" 

Comments

1
print("INFORMATION\n"
      "-----------\n"
      "Variable1: {}\n".format(var1),
      "Variable2: {}".format(var2)
      )
In [24]: print("INFORMATION"'\n'
   ....:           "-----------"'\n'
   ....:           "Variable1: {}\n".format(var1),
   ....:           "Variable2: {}".format(var2)
   ....:           )
INFORMATION
-----------
Variable1: 2
Variable2: 5


print("INFORMATION",
      "-----------",
      "Variable1: {}".format(var1),
      "Variable2: {}".format(var2),
      sep='\n')
In [30]: print("INFORMATION",
   ....:       "-----------",
   ....:       "Variable1: {}".format(var1),
   ....:       "Variable2: {}".format(var2),
   ....:       sep='\n')
INFORMATION
-----------
Variable1: 2
Variable2: 5

Comments

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.