Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
array
communitycreator

What is array.tounicode() in Python?

Eman Kashif

Overview

Python is a high-level programming language that provides functionalities for several operations. The array module comes with various methods to manipulate array data structures.

The function array.tounicode() converts an array to an unicode string.

Syntax

uni = array.tounicode()

Parameters

This function does not take in any arguments.

Return value

This function returns a unicode string. The array passed must be of type u. Otherwise, the function returns a ValueError.

Example

#import module
from array import array

#initialize array with unicode characters
array_one = array("u", ['a','b','c','d'])

#initialize array with unicode characters
array_two = array("u", ['e','f','g'])

print (array_one)
#convert array to unicode string
uni_one = array_one.tounicode()
print(uni_one)
print ("\n")

print (array_two)
#convert array to unicode string
uni_two = array_two.tounicode()
print(uni_two)

Explanation

  • Line 2: We import the array module.

  • Lines 5 and 8: We initialize arrays with unicode characters.

  • Lines 12 and 18: We convert arrays to unicode strings using array.tounicode().

RELATED TAGS

python
array
communitycreator
RELATED COURSES

View all Courses

Keep Exploring