0

I've got a two letter word that I'd like to attach to a double digit number. The word is an integer and the number is a string. Say the name of the number is "number" and the name of the word is "word". How would you make it print both of them together without spaces. When I try it right now it still has a space between them regardless of what I try. Thanks !

3 Answers 3

2
'{}{}'.format(word, number)

For example,

In [19]: word='XY'

In [20]: number=123

In [21]: print('{}{}'.format(word, number))
XY123
Sign up to request clarification or add additional context in comments.

Comments

2

The print function has a sep parameter that controls spacing between items:

print(number, word, sep="")

If you need a string, rather than printing, than unutbu's answer with string formatting is better, but this may get you to your desired results with fewer steps.

Comments

0

In python 3 the preferred way to construct strings is by using format

To print out a word and a number joined together you would use:

print("{}{}".format(word, number))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.