artificial intelligence, network, programming @ Pixabay

You might think that you can concatenate lists of integers together, but if you try it out, you’ll find that they don’t work. This is because Python’s “int” type is not the same as a list. Lists are mutable objects while “int” values are immutable (unchangeable). This means that when we try to combine them, Python will either crash or give an error message.

code, coding, computer @ Pixabay

Problem: Lists are mutable objects while “int” values are immutable (unchangeable). This means that when we try to combine them, Python will either crash or give an error message. So you can only concatenate lists of the same type together. This is because Python’s list container and integer types are incompatible – they don’t have compatible data representations in memory.

We’ll get a runtime exception if we try this operation out as shown below. >> [l] + [“a”] Traceback (most recent call last): File “” , line 11, in l+[“a”] TypeError: cannot concat int to str >> [(l)] + [[‘a’] for i.

LEAVE A REPLY

Please enter your comment!
Please enter your name here