Q: i need help combining strings that contain numbers i am looking to combine strings containing numbers without adding them together in Python.
Today is the first day of my scripting class and I am struggling with this specific concept. i know that number1 + number2 adds the numbers together but im not sure how to combine them without adding them. Ive tried 'number1' + 'number2' and many variations of similar things.
# Input from the command line
# converted to an integer
import sys
number1 = int(sys.argv[1])
number2 = int(sys.argv[2])

# Your code goes here
newString = 
print(newString)


Program Failed for Input: 123 456
Expected Output: 123456


A: + works differently between integers and strings. For integers, it adds them as you'd expect. For strings, it concatenates the second string on the end of the first.
So, you need to make number1 and number2 into strings:
newString = str(number1) + str(number2)

In fact, since sys.argv will give you the numbers as strings in the first place, you can just not convert them to ints in the first place and then do number1 + number2.
You can convert a string back into an integer by simply doing int(newString), although in this case that doesn't seem to be necessary.

A: You can use string formatting options if you just want to concatenate them
a = 123
b = 456

f"{a}{b}"  # option 1
'123456'

"{}{}".format(a, b)  # option 2
'123456'

c = [a, b, b, a]

("{}"*len(c)).format(*c)  # unknown or variable inputs
'123456456123'

If you actually need an integer, then 'int' the result to make it an integer.
