Python is a readable, high-level language used to move from small utility scripts toward complex, maintainable software. Its syntax resembles written English, lowering the barrier for new programmers while supporting rapid development. section 1.0 section 1.1.2
Python has grown beyond its historical scripting role. It is applied across enterprise software and disciplines including robotics, machine learning, chemistry, and internet services. section 1.1 section 1.1.1
Python supports practical habits for building larger systems:
- Use the REPL for quick experiments and short feedback cycles. section 1.7.1
- Move longer-lived or reusable code into modules and functions. section 1.7.1
- Plan changes and refactor as software grows instead of relying on repeated quick fixes. section 1.7.1
- Use Python’s tools and dynamic typing without forcing design patterns where they do not fit. section 11.2.1
Sorting state capitals
A REPL experiment starts with a dictionary of states and capitals, extracts the values, encounters an error when calling sort on dict_values, and then uses sorted(capitals). Wrapping the logic in a function or module makes it reusable. section 1.7.1
Listing 1.1. Getting the United States capitals in alphabetical order
>>> us_capitals_by_state = { #1
'Alabama': 'Montgomery',
'Alaska': 'Juneau',
...
}
>>> capitals = us_capitals_by_state.values() #2
dict_values(['Montgomery', 'Juneau'])
>>> capitals.sort() #3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict_values' object has no attribute 'sort'
>>> sorted(capitals) #4
['Albany', 'Annapolis', ...]
Inspect the interactive state-capitals example, including the failed sort attempt and the corrected sorted call. section 1.7.1

























