+ 1

How to create char ARRAY ?

Here it's considering as a single string How can I get an array ['a','b','c'] https://code.sololearn.com/cr2eclG8t8Uk/?ref=app

1st Sep 2022, 5:47 AM
Levi
Levi - avatar
9 Respuestas
+ 6
Levi , you may be irritated by the output result when printing the array. there is no string type for array, but you can use 'u' for an array of type unicode charracter. the code: import array a=array.array('u', ['a', 'b']) print(a) a.append('x') print(a) shows: array('u', 'ab') array('u', 'abx') this is how the character array is represented. you can find here more info about python array module. https://docs.python.org/3/library/array.html keep in mind that it is used only very rarely. most codes are using python lists or numpy arrays.
1st Sep 2022, 2:18 PM
Lothar
Lothar - avatar
+ 4
Levi array stores only one type of data list stores any combination of different types of data you can store a text file along with a integer in list which would not be possible in an array
2nd Sep 2022, 5:29 AM
Harsha S
Harsha S - avatar
+ 4
Levi , as Harsha S already mentioned is array not able to hold different types of data at a time. array is optimized for performance, list has a wide range of use cases. this results in a higher memory consumption.
2nd Sep 2022, 5:27 PM
Lothar
Lothar - avatar
+ 3
Lothar An additional question regarding arrays, Why arrays is more compact in memory size when compared to list ?
2nd Sep 2022, 3:43 AM
Levi
Levi - avatar
+ 1
try to print the individual elements of the array try to print the length of the array try assigning 'abc' as a single element to the array
1st Sep 2022, 6:32 AM
Harsha S
Harsha S - avatar
+ 1
I think you are looking for list out of string You may use split method on string
3rd Sep 2022, 3:58 AM
Pavneet Ghai
Pavneet Ghai - avatar
0
to create an array using character data type i.e char arr[4];
3rd Sep 2022, 4:47 AM
Mahima Bhardwaj
Mahima Bhardwaj - avatar
- 1
What is <br> role in html?
2nd Sep 2022, 8:16 PM
Under in all
Under in all - avatar