2016-07-18 152 views

回答

0

是我終於找到了答案。
我們可以在3忽略換行:

  1. 「+」(串聯)
    例如:

    a = sachin 
    b = 'tendulkar' 
    a += b 
    print(a) 
    
  2. 使用「」(逗號)見上回答

  3. 通過使用write()函數:

    import sys 
    write = sys.stdout.write 
    write('20) 
    write('17') 
    

    輸出:

    2017 
    

    write()方法不換行字符( '\ n')添加到字符串的末尾。

2

我相信你正在使用Python2.x。您可以嘗試以下方法:

  1. 使用尾隨逗號。從未來的

    from __future__ import print_function 
    print(a,end='') # no new line will be printed 
    

而對於Python3.x以下將做

print a, # no new line will be printed 
  • 使用打印功能。 Do not need to import print function

     print(a,end='') 
    
  • +0

    Thak you ... but buddy我使用3.5.2, –

    1

    你可以試試這個也

    print(repr(b), a) # ',' will avoid the newline

    +0

    謝謝..除此之外 –