QNA > Q > Qual È Lo Scopo Di "End" In Python?

Qual è lo scopo di "end" in Python?

È una parola chiave per la funzione print(), che è stata introdotta in Python 3. L'argomento della parola chiave end= detta cosa dovrebbe essere stampato dopo che tutti gli argomenti sono stati stampati:

  1. >>> for num in range(10): 
  2. ... print(num, end=' ') 
  3. ... 
  4. 0 1 2 3 4 5 6 7 8 9 

The above end= argument causes a space to be printed after each number, rather than the default newline character.

La funzione print() ha anche un argomento sep= che controlla cosa viene stampato tra le voci:

  1. >>> print('foo', 'bar', 'baz', sep='+++') 
  2. foo+++bar+++baz 

If you’re currently stuck using Python 2, you can ditch the print statement and avail yourself of the much more flexible and powerful print() function by importing it from the __future__ module:

  1. Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12) 
  2. Type "help", "copyright", "credits" or "license" for more information. 
  3. >>> from __future__ import print_function 
  4. >>> print('foo', 'bar', 'baz', sep='...') 
  5. foo...bar...baz 
  6. >>> 

Di Lhary Cailler

Can anybody elaborate the use of c_ in numpy? :: How to convert int to byte in Python
Link utili