Explanation:
✅ Line 1:
This imports Python's built-in array module (used for typed arrays).
✅ Line 2:
-
Creates an array of type 'i', which means signed integers.
-
The array a now holds: [1, 2, 3].
❌ Line 3:
Here’s the problem:
'4' is a string, not an integer.
-
But the array is declared to hold only integers ('i').
-
So appending a string causes a TypeError.
❗ Error Message:
✅ Correct Version:
To fix the error, pass an integer:
Output:
Summary:
array.array('i', ...)only accepts integers.Passing a string (even '4') causes a TypeError.
Python Projects for Real-World Applications


0 Comments:
Post a Comment