Using .append() With Arrays in Python
Many other structures in Python have an
.append() method. They can be from a wide variety of modules, some standard to Python, some written by others. You’ll finish up this course by seeing two of them, the array and the double-ended queue.
00:40 All of the elements must be of the same type, not mixed as you see in lists. And you can only use certain types, like integers, characters, decimal values—things that are considered simple types in the language C. Arrays do some things much more efficiently than lists, so if you’re working only with numeric data, you might consider an array instead of a list.
Create a new integer array with initial values
3 and look at its representation. It displays itself with the type that it is and what the array currently looks like. You can inspect individual elements,
And that integer will be cast to the decimal value
4.0 and then appended to the array. So the array is still an array of floats, it just took the integer, changed it by casting it to a float, and then appending it.
Become a Member to join the conversation.