You can use typing for recent python version (tested on 3.9), as suggested by @Netwave in the comments:

def my_function(a: list[str]):
  # You code

Which will lint as expected:

Answer from KawaLo on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_strings_are_arrays.asp
Python Strings Are Arrays
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to create array of strings in python
How to Create Array of Strings in Python - Spark By {Examples}
December 20, 2024 - How to create an array of strings in Python? you can create an array of strings using the list. Python does not have a built-in data Type. You can
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-create-string-array-in-python
How to Create String Array in Python ? - GeeksforGeeks
July 23, 2025 - Python array module is specifically used to create and manipulate arrays in Python. Although the array module does not support string datatype, but it can be modified to store the Unicode characters as strings.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-import-an-array-of-string-in-Python-or-what-is-the-type-code-to-make-an-array-of-string-if-any
How to import an array of string in Python or what is the type code to make an array of string (if any) - Quora
It has lists and other sequence types, which you can index like arrays. If you have a supply of strings from somewhere and you want to put them in an array (list) then you often start with an empty list and append the strings, one by one.
Top answer
1 of 2
3

If you fix the lenght of the array, you can just create a list with a none value

keyword = [''] * 100   # list of 100 element
keyword[0] = 'Blue Light Glasses'
keyword[1] = "Tech Fleece Joggers"

You can also create a empty list and add element in this list

keyword = list()
keyword.append('Blue Light Glasses')
keyword.append('Tech Fleece Joggers')
print(keyword)

Output:

['Blue Light Glasses', 'Tech Fleece Joggers']
2 of 2
0

there isn't a way in python to declare a array of a fixed lenght but there are some "tricks" to do this as:

lenght = 100
# You are creating an array of 100 None items
listOfNone = [None] * lenght

Another thing you can't do is declare an array of that fixed value type (like string). You can create an array only made of string but at any time you could replace a string element of the array with an int for example. Here is an example:

lenght = 100
# Declaring an array made of 100 "a beautiful string" repeating
listOfStrings = ["a beautiful string"] * lenght 
# Replacing the tenth element with a 12 (type int)
listOfStrings[9] = 12
# You can check the type of the element in python by printing:
print(type(listOfStrings[9])) # This will print int
print(type(listOfStrings[8])) # This will print string. As you can see there are 2 types of var in the same list (python doesn't matter)
listOfStrings[24] = False #Placing a bool in the 25th element

There is a workaround to this: you can create a function that handles the array (or use a class too, but I don't know your Python level). I'm typing a basic function for you that you can adjust for your needs

def fillArrayWithElement(array, element):
    if not str(type(array)) == "<class 'list'>":
        # The array is not an array
        raise ValueError('The first parameter must be list type')
        return
    if not str(type(prova2)) == "<class 'str'>":
        # The element to add is not a string
        raise ValueError('The element must be str type')
        return
    array.append(element)
    return array
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values
Deprecated since version 3.3, will ... to 'w' typecode. Added in version 3.13. The actual representation of values is determined by the machine architecture (strictly speaking, by the C implementation). The actual size can be accessed through the array.itemsize attribute. ... A string with all available ...
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ string array in python
String Array in Python | Know List And Methods of String Array in Python
March 16, 2023 - String Array can be defined as the capacity of a variable to contain more than one string value at the same time, which can be called and accessed at any time in the program during the execution process.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
๐ŸŒ
Awkward-array
awkward-array.org โ€บ doc โ€บ main โ€บ user-guide โ€บ how-to-create-strings.html
How to create arrays of strings โ€” Awkward Array 2.9.0 documentation
['three', 'one', 'two', 'two', 'three', 'one', 'one', 'one'] --------- backend: cpu nbytes: 107 B type: 8 * categorical[type=string] Internally, the data now have an index that selects from a set of unique strings.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 61593059 โ€บ what-is-the-type-code-for-strings-in-python
arrays - what is the type code for strings in python? - Stack Overflow
For initializing arrays in python we need type code for that .I need to store strings in that array.So what type code i should use ? import array array.array(typecode,['abc','fes','fsfs'])
๐ŸŒ
Reddit
reddit.com โ€บ r/programminglanguages โ€บ array type annotation syntax: string[] -vs- [string]
r/ProgrammingLanguages on Reddit: Array type annotation syntax: String[] -vs- [String]
July 13, 2022 -

Just a little question on aesthetic preference and history...

When declaring a type that is an array of strings for example, which syntax do you prefer?

  1. String[] used in TypeScript and many other languages

  2. [String] used in Haskell, and maybe others?

While most of my programming is in TypeScript, and I've really only tinkered with Haskell a bit, to me, #2 already feels like it make more sense, because the strings are "inside" the array, so it kinda feels like the brackets should "surround" it.

And it feels even more logical when you have arrays of arrays, i.e. [[String]], because the inner arrays are "inside" the top-level array.

Whereas String[][] looks more like the arrays are "siblings" rather than nested.

Not huge deal either way, was just curious how others see it?

And any idea behind why any specific languages made their choice, rather than the other choice?

Top answer
1 of 5
67
I prefer Array[String]. [] should not just be array syntax, but generics in general. There's no reason to give array a special treatment. You should be able to replace Array with List or something else and not have to change any other part of the syntax. In Haskell [ ] is a list, and lists are given special treatment. They're linked lists and often not what you want anyway. All of Haskell's standard prelude gives lists a special treatment which is part of why there have been attempts to replace it with a better prelude. For example, functions like map are specific to lists, which is why the generic version, Functor, has to name it's map fmap because map is already taken. But since lists are functors, you can replace any instance of map with fmap and nothing will change. Obvious here that map would be better in the functor to begin with, and lists don't deserve the special treatment. Lists should instead be written the same as any other type in Haskell, for consistency. data List a = Nil | Cons a (List a) class Functor f where map :: f a -> (a -> b) -> f b instance Functor List where map :: List a -> (a -> b) -> List b = ... Pretty sure most Haskellers would agree. The reason it's this way is because Haskell's lists pre-date the introduction of typeclasses to the language.
2 of 5
36
In Futhark, for a long while, we had simply adopted Haskell's list type syntax: an array of i32s was written [i32], and a two-dimensional array of i32s was written [[i32]]. This was both familiar and readable. However, some timer later we extended Futhark with size types, by which individual dimensions of an array could be annotated with a variable or constant indicating its size. For example, a function for matrix multiplication could be defined as: def (x: [[i32,m],n]) (y: [[i32,p],m] y): [[i32,p],n] = ... This nicely describes the invariant that an n by m matrix can be multiplied with an m by p matrix, yielding an n by p matrix. Apart from having an effect on the aesthetics and readability of code, the notation for types is also important when communicating the semantics of the language. For example, using this notation for array types, we can describe the type of map as: map : (a -> b) -> [a,n] -> [b,n] This type concisely describes that the output array of map has the same outer size as the input array, while nothing is said about any inner sizes (a and b can be any type). In general, any array type [t] could receive a size annotation as [t,n], meaning "array of n values of type t". The motivation for placing the size to the right of the element type was due to the intuition that such annotations were an optional "extra". However, this design turned out to have a major disadvantage: array types had to be read right-to-left. For example, a three-dimensional integer matrix of size k by n by m would be written [[[i32,m],n],k]. This proved very confusing in practice. One simple solution would be to simply move the sizes to the left of the element type. Our matrix multiplication function would then be: def (x: [n,[m,i32]]) (y: [m,[p,i32]] y): [n,[p,i32]] = ... But while we were mucking about with the syntax anyway, we decided on more radical changes. The Haskell notation works well when you have only a small number of dimensions, but becomes unwieldy fast. How many dimensions does [[[[[i32]]]]] have? It is also annoying that the element type is hidden all the way in the middle. Deeply nested lists of lists are uncommon in Haskell, but not particularly so in Futhark. We considered a C-style syntax, such as i32[k][n][m]. This looks less noisy, but unfortunately composes badly. When adding a new outer dimension (or stripping the outermost), we have to make modifications in the "middle" of the type. This makes it harder to give type signatures. Let us consider map again: map : (a ds -> b ds') -> a[n]ds -> b[n]ds' Here, ds and ds' are some arbitrary (possibly empty) list of shape declarations. This is very awkward! Things are much simpler if we move the dimensions to the left of the element type: [k][n][m]i32. Now, for any type t, an array of n ts is just [n]t The type of map can be written as: map : (a -> b) -> [n]a -> [n]b I think this allows simpler notational composition, and so it's the notation we ended up picking. Although the [k][n][m]i32 notation looks weird at first glance, it has been quite comfortable to use in practice. I think it's also used in some other languages. It also fits well with the idea that "array" is a type constructor, and type constructors (like all functions) go to the left of their operand. It's just a type constructor that looks weird.
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ blog โ€บ 16 must know array of strings function in python
16 Must Know Array of Strings Function in Python - Python Pool
June 14, 2021 - In Python, we donโ€™t have a ... by itself. An array of strings can be defined as the capacity of a string to contain more than one string value at the same time....
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ basics.strings.html
Working with Arrays of Strings And Bytes โ€” NumPy v2.5.dev0 Manual
Using NumPy indexing and broadcasting with arrays of Python strings of unknown length, which may or may not have data defined for every value. For the first use case, NumPy provides the fixed-width numpy.void, numpy.str_ and numpy.bytes_ data types. For the second use case, numpy provides numpy.dtypes.StringDType.
๐ŸŒ
PragmaticLinux
pragmaticlinux.com โ€บ home โ€บ how to create an array of strings in python
How to create an array of strings in Python - PragmaticLinux
September 27, 2022 - This article explains how to create an array of strings in Python, including code examples for iterating over the string array.
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ typed-arrays-and-strings
Typed Arrays and Strings (Video) โ€“ Real Python
If I ask Python what is the type of the string "abc", I get back the <class 'str'> (string). 06:20 If I do the same thing with the first letter in that string, I also get back the <class 'str'>. So characters are single-letter strings and strings are multi-letter strings. 06:33 In the next lesson, Iโ€™m going to talk about dealing with arrays of binary data.
Published ย  February 23, 2021
๐ŸŒ
New York University
physics.nyu.edu โ€บ pine โ€บ pymanual โ€บ html โ€บ chap3 โ€บ chap3_arrays.html
3. Strings, Lists, Arrays, and Dictionaries โ€” PyMan 0.9.31 documentation
For other tasks, lists work just ... to arrays. Strings are lists of keyboard characters as well as other characters not on your keyboard. They are not particularly interesting in scientific computing, but they are nevertheless necessary and useful. Texts on programming with Python typically ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ user โ€บ basics.strings.html
Working with Arrays of Strings And Bytes โ€” NumPy v2.1 Manual
Using NumPy indexing and broadcasting with arrays of Python strings of unknown length, which may or may not have data defined for every value. For the first use case, NumPy provides the fixed-width numpy.void, numpy.str_ and numpy.bytes_ data types. For the second use case, numpy provides numpy.dtypes.StringDType.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.arrays.StringArray.html
pandas.arrays.StringArray โ€” pandas 3.0.1 documentation
>>> pd.array(["1", 1], dtype="object") <NumpyExtensionArray> ['1', 1] Length: 2, dtype: object >>> pd.array(["1", 1], dtype="string") <ArrowStringArray> ['1', '1'] Length: 2, dtype: string