From the course: Python Standard Library Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using efficient arrays

Using efficient arrays - Python Tutorial

From the course: Python Standard Library Essential Training

Start my 1-month free trial

Using efficient arrays

- [Instructor] Regular lists in Python don't have any restrictions on the kinds of data they can contain. You can have a list that contains numbers, strings, objects and so on, in any order that you like. But when you know in advance that the type of data that your code will be working with are all the same type, it can more efficient and help to prevent bugs by using Python's efficient arrays feature. This feature lets you create arrays that are limited to a specific type of data and to do this you use the array module. So let's open up efficient_start.py. And here at the top you can see I've imported the array module, and from the array module, I've imported the array data type. To create an array for a type of data you specify a letter code that indicates the type of data that the array will contain. So to create an array of integer numbers, I use the code that you see here. So I have my variable name, and then I use the array constructor. The first letter indicates I'm going to be…

Contents