What is the output of this code snippet?
squares = [1, 4, 9, 16, 25] print(squares)
This puzzle introduces the simple but powerful list data structure in Python. You have to search very hard to find an algorithm that is not building upon a list. Many famous algorithms such as quicksort are based on only one list as core data structure.
Wikipedia defines a list as
“an abstract data type that represents a countable number of ordered values”.
It is abstract because it is independent of the concrete data type of the values in the list.
In the Java programming language, you must use redundant natural language function calls such as
get(i) to access a list value. In Python, this is much easier. You access the
i-th element in a list
l with the intuitive bracket notation
l[i]. This notation is consistent for all compound data types such as strings and arrays.
This leads to small and repeated time savings during programming. The time savings of millions of developers add up to a strong collective argument for Python.
Are you a master coder?
Test your skills now!
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.