-4

I am a noob so this question maybe a crap for you.

As written in title, I want to stop print() from printing space while using ,.

I have code for that :

i = 1
print (i,"2")

Output = 1 2

Expected Output = 12

3 Answers3

3

You can use f-strings instead:

i = 2
print(f"{i}2")
kalehmann
  • 4,821
  • 6
  • 26
  • 36
fgoudra
  • 751
  • 8
  • 23
  • This will raise a SyntaxError. Maybe you mean: `print("{}2".format(i))` – LaurinO Jun 03 '19 at 08:26
  • 2
    @LaurinO This is a new feature called f-strings which was introduced in Python3.6, it runs fine: https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python – kalehmann Jun 03 '19 at 08:39
  • @kalehmann: You are right. I just tried it in a newer Python version. Thx, I did't know. – LaurinO Jun 03 '19 at 09:04
2

Try this:

i = 1
print(i,"2",sep='')

or by use of str.format():

i = 1
print("{}2".format(i))
LaurinO
  • 136
  • 6
0

This may not be a good practise, but it certainly gets the job done:

print(i+"2")

Also as a note you should have i = "1" as it should be a string.

Bytes2048
  • 344
  • 1
  • 6
  • 16