Can't get string array to print

Can't get string array to print
0

#1

I am trying to loop through an array of strings and get it to print but I keep getting this error:
TypeError: an integer is required (got type str)

This is what I have so far because I erased everything else I had written.

from array import *

days = array(‘B’, [‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’])

I know I can figure out the loop but how do I get it to print?


#2

https://docs.python.org/3/library/array.html

This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which is a single character.

You can’t put strings in an array that is restricted to only containing unsigned char values (which is what 'B' indicates).


#3

Is this what you’re trying to do?


#4

Yes. I had that done but isn’t that a list?

It might be that I am overthinking it but don’t you need to import array and add the typecode?


#5

From looking at the documentation, array doesn’t support arrays of strings.


#6

Try this:

days = [‘monday’, ‘tuesday’, ‘wednesday’,‘thursday’, ‘friday’]
for day in days:
print(day)