0

how do I print two things in one row so that it isn't in a new line

print ("alright " + name)
howareyou = input("How are you?: ")

if howareyou == "good" or "Good" or "Alright" or "GOOD" or "bad" or "BAD":
    print ("Alright")
else:
    print ("What is that?")

When I run it

alright 
How are you?: 

So, how do I put them in the same line?

Niloct
  • 9,491
  • 3
  • 44
  • 57
rZero3
  • 1,659
  • 1
  • 12
  • 8
  • Also: http://stackoverflow.com/q/4390942/748858 (for python2.x) – mgilson Mar 22 '14 at 23:24
  • 1
    On a side note, you are using the `or` operator incorrectly. See [here](https://stackoverflow.com/questions/15112125/if-x-or-y-or-z-blah) for reference. –  Mar 22 '14 at 23:30
  • Ok thanks guys but i got it: howareyou = input("Alright " + name + " how are you?: ") – rZero3 Mar 23 '14 at 13:41

2 Answers2

5

python2:

print "hello",
print "there"

note the trailing comma. A trailing comma after a print statement suppresses the newline character. Note also that we do not put a space on the end of hello -- a trailing comma for print also puts a space after the string.

It works even in the compound statement with multiple strings: python2:

print "hello", "there", "henry",
print "!"

prints:

hello there henry !

In python3:

print("hello ", end=' ')
print("there", end='')

the default value of the end parameter for the print function is '\n', which is the newline character. So in python3 you suppress the newline character yourself by specifying the end character to be an empty string.

Note: You can use any string as the end symbol:

print("hello", end='LOL')
print("there", end='')

prints:

helloLOLthere

You could, for instance, make end=' ' to avoid adding spaces to the end of your printed string. That's very useful :)

print("hello", end=' ')
print("there", end='')
Pod
  • 3,938
  • 2
  • 37
  • 45
  • 1
    And, to finish this off, to comply with python2.6+, you could use the python3 version with `from __future__ import print_function` – mgilson Mar 23 '14 at 01:56
2

In Python 3:

print('Some stuff', end='')

In Python 2:

print 'Some stuff',
grayshirt
  • 615
  • 4
  • 13