π Reading¶
βοΈ Section undergoing re-write
Feel free to peruse, but there are likely errors or miscommunicated ideas.
π Reading Python¶
Code is more often read than written
- Guido van Rossum (creator of the Python programming language)
Python is famous for being a readable language. The words we use in Python, and the way we string words together, is very reminiscent of English.
For example, if we wanted to tell our friend to open Google Maps for various countries, we could write:
Repeat the following for each country in this list of countries:
"Canada", "Italy", "Cambodia", "Kenya", and "Japan"
- Type https://www.google.com/maps/place/ (the Google Maps url) into a new browser tab
- Add the country to the end of the url, like https://www.google.com/maps/place/Canada
- Hit enter to go to the website
Try it yourself
Try typing this example into Thonny and running it using the green 'run' button.
Now, although Python is a readable language, this example is still probably confusing. Take some time to study the example, and come up with 3 things that confuse you.
Possibly confusing things
- What does
import webbrowsermean? - What's with the underscore in
maps_url? - Why is
webbrowser.open_new_tab(MAPS_URL + country)indented? - Why do we need the
.and the round brackets(and) - What's with the colon (
:), or the square brackets ([and])?
To develop our fluency, we will practice translating between English and Python.
Examples¶
For each example:
- Explain in English what you think the code does.
- Then type the code into the Thonny code editor (avoid copy-pasting, it is essential to develop muscle memory for writing Python)
- Finally, run it to see if you were right
Type everything
Type all the examples to better remember Python
--8← "2-Reading-and-Writing/reading.txt"