Chapter 3.1 - Exercise
Getting help
Python has a builtin help system which describes and explains things:
In an interactive python session you can use help()
on almost anything to display a help page:
help(len)
Help on built-in function len in module builtins:
len(obj, /)
Return the number of items in a container.
Note: The help page is opened using the less
command. Refer to chapter 1.2 if you are unsure about how to navigate it (hint: Try the cursor keys and "q").
Planets
Copy this into an interactive python session:
planets = ["Mercury", "Vinus", "Mars", "Earth", "Saturn"]
Fix the planet name
"Vinus" has a typo in it and should be called "Venus". Fix this by replacing the element.
Sort the planets
Your objective is to sort the list of planets alphabetically and print it to the terminal.
Hint: The list of planets might have a function for that. Use the builtin help, to figure out how to do that.
Reverse the planets
Print the list of planets in reverse order.
Remove planets
Remove the one planet from the list, where humans, as of 2023, already have set foot on.
Length of a string
How long is the string "The quick brown fox jumps over the lazy dog"?
Next chapter
Coming right up: chapter 3.2 which explains loops and contains.