Get The Most Affordable Hosting in the World!

Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.

Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!

Get Started Now!

Since the array object behaves very much like a sequence, you can perform indexing and slicing operation with it.

Example

 
import array as arr a = arr.array('i', [1, 2, 3]) #indexing print (a[1]) #slicing print (a[1:])

Changing Array Items

You can assign value to an item in the array just as you assign a value to item in a list.

Example

 
import array as arr a = arr.array('i', [1, 2, 3]) a[1] = 20 print (a[1])

Here, you will get "20" as the output. However, Python doesn't allow assigning value of any other type than the typecode used at the time of creating an array. The following assignment raises TypeError.

 
import array as arr a = arr.array('i', [1, 2, 3]) # assignment a[1] = 'A'

It will produce the following output −

TypeError: 'str' object cannot be interpreted as an integer



The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.
Byla tato odpověď nápomocná? 1 Uživatelům pomohlo (1 Hlasů)