0% found this document useful (0 votes)
2 views1 page

Python Lists: Adding & Deleting Items

Uploaded by

pro.diven3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Lists: Adding & Deleting Items

Uploaded by

pro.diven3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming Lesson 6: Using lists in a Python Program

Lists are used to store multiple items in a single variable.

Ex:

days = [“Sunday”, “Monday”, “Tuesday”, “Friday”]

Name of the list 0 1 2 3 (positions of the objects)

Question

a) Write the Python code statement to add “Saturday” to the end of the list.
b) Write the Python code statement to delete the object Monday from the given list.

Making a random choice from a list using in built modules and functions.

Python has a built- in modules. Ex: turtle, random, time

Python random module provides a set of functions to generate outputs.

Ex: To select a random integer within a specified range.

print([Link](10)) # Output: An integer from 0 to 9 inclusive

print([Link](1, 10)) # Output: An integer from 1 to 10 inclusive

The choice() function returns a random element from a sequence or a list.

Python time module It allows functionality like getting the current time, pausing the program from
executing.

The program below uses both modules.

You might also like