From the course: Programming Foundations: Beyond the Fundamentals

Collections in other languages - Python Tutorial

From the course: Programming Foundations: Beyond the Fundamentals

Collections in other languages

- Collections, like Python's lists and Python's dictionaries, let you organize related data. And we're primarily going to be using Python in this course, but it's important to understand that across programming languages, collections can actually vary a lot. In Python, each item in a list can be of any data type. So you could combine strings, numbers, and other types of data like bullion values, all on the same list. But other languages like C++ require that all values in this type of collection must be of the same data type. For instance, containing all strings or all numbers but no combination of these or other types of data. Another factor in collections is whether the data stored in them can be changed in python lists or python dictionaries, you can add or remove items or you can change the value of an existing item. We refer to these collections as mutable, meaning they can be changed, but some programming languages support collections that are immutable, meaning that their values cannot change after they're created. In fact, Python itself lets you create a collection known as a tuple, which is essentially an immutable list. Once you create a tuple, you can't change it. And this can be especially useful in coding when you're working on a large project, for instance, with other developers. Using an immutable collection like a tuple can help ensure that data that shouldn't be altered like a collection of locations remains unchanged. Even when programming languages share collection types a wide variety of names are used for common collections. For instance, what's known as a list in Python is called an array in JavaScript and C++. Python dictionaries are known variously as associative arrays, maps or tables. So as you build more complex programs, your organizational requirements may influence which language you choose based on the characteristics it offers for its collections.

Contents