Python Lists and Dictionaries
What I learned from this project...
Assign items to a list with an expression of the form:
Assign items to a list with an expression of the form:
list_name = [item_1, item_2]
Replace: numbers[0]="3"
Then the first number 5 will be replaced by 3
The code used above is the Python index code that I've learned from the lessons from before:
The code used above is the Python index code that I've learned from the lessons from before:
Append: A list doesn't have to have a fixed length. You can add items to the end of a list any time you like!
Slicing Lists and Strings: Think of strings as lists of characters: each character is a sequential item in the list, starting from index 0.
We can also
insert
items into a list.
Sometimes you need to search for an item in a list.
Example:
Write a statement in the indented part of the
for
-loop that prints a number equal to 2 * number
for every list item.
The result is...All the numbers were multiplied by 2.
If your list is a jumbled mess, you may need to
sort()
it.
Items can be removed from a dictionary with the
del
command
Sometimes you need to remove something from a list.
No comments:
Post a Comment