1

So I'm currently losing sleep over this problem I have and I would be grateful if someone could help me.

The problem itself is simple. I have two variables, let's call them x and y and I want these two variables to make one number: z. so for example let x = 3 and y = 7 I need z to be 37

I know the answer is simple as well but I just can't find the search words for it. Thanks in advance!!

3 Answers 3

7

There are many ways to do this. Perhaps the most simple is to use strings:

>>> int(f'{x}{y}')
37

Or you can just use math. This is also very simple, especially if you know that each of your integers is a single digit:

>>> x*10+y
37
Sign up to request clarification or add additional context in comments.

Comments

3

Here you go:

str(x) + str(y)                                                                                                                                                                     
#  '37'

or

int(str(x) + str(y))                                                                                                                                                                
# 37

Comments

0

Just simply convert them to str:

numbers = [1, 2, 3, 4]
result = ''
for n in numbers:
  result += str(n)
print(result)
# 1234

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.