Coding for Kids: The Complete Guide Python Programming for kids, Learn to Code with Games by Alice Guillen

Coding for Kids: The Complete Guide Python Programming for kids, Learn to Code with Games by Alice Guillen

Author:Alice Guillen [Guillen, Alice]
Language: eng
Format: epub, azw3, mobi
Published: 2020-08-26T22:00:00+00:00


Removing Parameters

We have learned how to insert objects into a list, and how to slice a list. Now another command I want you to meet is remove().

The remove method takes one parameter, which is the value of the entry to remove. By values, we mean the information stored in each list entry. Sometimes, you may want to make a twin of your list so that you can work on that win while keeping the original. That is what we will be doing with our list now.

Go over to your shell and make a copy of our list by typing

test_list=another_list

Here is what we want to do. We will try to remove an object from this list. Let us remove “do not” from our test_list. Can you do that?

Did you guess remove ( ) like we used insert ( )?

You are very smart!

We use commands like insert and remove to modify existing lists. So, we know that our command for remove will look like test_list.remove().

We will surely have to add a parameter that will be removed because, otherwise, the computer would not know which list entry to remove!

Therefore, our resulting command is

>>> test_list.remove("do not")

>>> test_list

['I', 'like', 'mushroom', 'or', 'tomatoes', 'in', 'my', 'pizza.']



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.