Home python How to display a list of two lines by one call feature...

How to display a list of two lines by one call feature Print ()




Is it possible to output a similar list in two lines without causing twice print ()?

print ('rows:', len (a), ';', 'columns:', Len (A [0]), '.', SEP = '')

To succeed in two lines:

Rows: Len (A) ;
Columns: Len (A [0]) .

and not in one:

Rows: LEN (A) ; Columns: Len (A [0]) .

Answer 1, Authority 100%

To split the strings, the \ N symbol is quite suitable. It is enough to put it in the place where the row transfer is needed.

I also wanted to see that it is clearly used to use the corresponding Python capabilities for formatted output, for example, formatting method:

print ('rows: {}; \ NStolbtsov: {}.'. Format (Len (A), Len (A [0])))

So immediately becomes clearer the structure of the recorded information.

You can even write this:

print ('rows: {}; \ n'
   'Columns: {}.'. Format (Len (A), Len (A [0])))

Sometimes the Formatting Operator % :

print ('rows:% s; \ n'
   'Columns:% s.' % (Len (A), Len (A [0])))

Record with its use, mostly shorter, but maybe less understandable.

Answer 2

Try to use “\ n”. Must work.

Answer 3

print ('rows:', len (a), ';', '\ NStolbtsov:', Len ( A [0]))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions