Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Create a List of Strings in Python
Next article icon

To create a string array in Python, different methods can be used based on the requirement. Alistcan store multiple strings easily,NumPy arrays offer more features for large-scale data and thearray module provides type-restricted storage. Each method helps in managing collections of text values effectively.

Using List

The simplest and easiest way to create any type of array in Python is by using List data structure. It is the most widely used method to create an array. There are various ways to create array using list.

Direct Initialization

In this method, when a list array is created, the values are assigned during the declaration. Later on an element can be added or removed from this array.

Python
arr=["Geeks","for","Geeks"]print(arr[1])

Output
for

Using Numpy Arrays

Numpy module in Python is used for working with array. Using the numpy module's array() function, a string array can be created easily.

Python
importnumpyasnparr=np.array(["Geeks","for","Geeks"])print(arr)print(arr[2])

Output
['Geeks' 'for' 'Geeks']Geeks

Using Array Module

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.

Python
fromarrayimportarrayarr=array('u',"GeeksforGeeks")print(arr[4])

Output
s

Note: The String array created using the array module cannot store multiple string values, but rather takes a string and stores its individual characters as elements.

Related Articles:


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp