Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 94
Chapter Summary
ОглавлениеIn this chapter, we introduced the mutable list object and the immutable tuple object. We learned that lists enable us to store multiple values of different data types in the same variable and that each item in a list can be referenced using an index value. We also learned about list methods, which are actions that can be performed to or with lists. Lists are very useful when working with data sets that are made up of different types of data. We also learned about Python string operations, which are very useful when working with portions of strings. We learned that strings are immutable, so we are not able to modify portions of strings in place, but we are able to replace strings by assigning portions of a string or combinations of string portions using concatenation. We then learned how Python sequence operations can be used on strings and lists to do things like searching for values or counting how many times a value appears in a list of values. We also learned about tuples, which are immutable sequences. Tuples have important usages when we have sequences of elements that we do not want to change.
We also learned about Python dictionaries in this chapter and how we can define one. We learned a number of operations that are used to work with dictionaries to do things like returning information corresponding to a dictionary entry or adding or changing a dictionary entry. We then demonstrated using both tuples and dictionaries alongside each other in our code. We learned that tuples can be very useful for passing multiple values to a function and that dictionaries are very useful for looking up values that correspond to coded data, such as that found in the GSS data set.
In the next chapter, we will cover control logic and loops, which enable the conditional and repeated execution of code statements but also can make it more challenging to detect and resolve errors. At the end of the next chapter, we will cover error handling as well as techniques that are useful in identifying and resolving logic errors in Python code.