From: Grady Knotts on 10 Aug 2010 01:17 In earlier versions of Python I can do: print 'A', print 'B' to print everything on the same line: 'A B' But I don't know how to do this with Python3 I've been trying things like: print('A',) print('B') and it prints two different lines. So, do I get two different print statements to output on the same line?
From: Benjamin Kaplan on 10 Aug 2010 01:34 On Mon, Aug 9, 2010 at 10:17 PM, Grady Knotts <gradyknotts(a)gmail.com> wrote: > In earlier versions of Python I can do: > print 'A', > print 'B' > to print everything on the same line: 'A B' > > But I don't know how to do this with Python3 > I've been trying things like: > print('A',) > print('B') > and it prints two different lines. > > So, do I get two different print statements to output on the same line? > >>> help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline.
From: Navkirat Singh on 10 Aug 2010 01:59 On 10-Aug-2010, at 11:04 AM, Benjamin Kaplan wrote: > On Mon, Aug 9, 2010 at 10:17 PM, Grady Knotts <gradyknotts(a)gmail.com> wrote: >> In earlier versions of Python I can do: >> print 'A', >> print 'B' >> to print everything on the same line: 'A B' >> >> But I don't know how to do this with Python3 >> I've been trying things like: >> print('A',) >> print('B') >> and it prints two different lines. >> >> So, do I get two different print statements to output on the same line? >> > > >>>> help(print) > Help on built-in function print in module builtins: > > print(...) > print(value, ..., sep=' ', end='\n', file=sys.stdout) > > Prints the values to a stream, or to sys.stdout by default. > Optional keyword arguments: > file: a file-like object (stream); defaults to the current sys.stdout. > sep: string inserted between values, default a space. > end: string appended after the last value, default a newline. > -- > http://mail.python.org/mailman/listinfo/python-list One method of doing this: Use the join method of the string: print( "".join( [ 'A' , '<space> B' ] ) This will give you : 'A<space>B' I have used extra spaces just for clarity. Hope this helps ! Nav
From: Steven D'Aprano on 10 Aug 2010 03:58 On Tue, 10 Aug 2010 00:17:03 -0500, Grady Knotts wrote: > In earlier versions of Python I can do: > print 'A', > print 'B' > to print everything on the same line: 'A B' > > But I don't know how to do this with Python3 I've been trying things > like: > print('A',) > print('B') > and it prints two different lines. > > So, do I get two different print statements to output on the same line? print("Hello", end=' ') print("world") outputs: Hello world -- Steven
|
Pages: 1 Prev: File Manager in Tkinter Next: delegate functions to member |