0

print(*[1,2,3]) outputs as: 1 2 3 print(*[1,2,3],sep='') outputs as: 123, which is string type.

Is there any way to print [1,2,3] as integer type 123

letmecheck
  • 1,183
  • 8
  • 17

1 Answers1

2
l = [1, 2, 3]
print(int(''.join(str(e) for e in l)))
RedEyed
  • 2,062
  • 1
  • 23
  • 26
  • you are converting `int` to `str` and again to `int`. is there a way that directly from `int` array to `number` in python? – letmecheck Jun 29 '18 at 12:41
  • There isn't. `int` is an immutable object in python. – RedEyed Jun 29 '18 at 12:42
  • Even if it was mutable, what algorithm would you offer? You can concatenate bytes, like `int.from_bytes([1, 2, 3], byteorder="big")`, but you will not get `123` because of binary concatenation – RedEyed Jun 29 '18 at 12:50