Changes

Jump to: navigation, search

OPS435 Python Lab 3

12 bytes added, 10:14, 29 January 2018
PART 2 - Manipulating Items in Lists
:#In addition to using functions to manipulate lists, there are functions that are useful to provide '''information''' regarding the list such as number of elements in a list, the smallest value and largest value in a list:<source lang="python">
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
lengthOfList length_of_list = len(list_of_numbers) # Returns the length of the listsmallestInList smallest_in_list = min(list_of_numbers) # Returns the smallest value in the listlargestInList largest_in_list = max(list_of_numbers) # Returns the largest value in the list
# Notice how the long line below is wrapped to fit on one screen:
print("List length is " + lengthOfList length_of_list + ", smallest element in the list is " + smallestInList smallest_in_list + ", largest element in the list is " + largestInListlargest_in_list)
</source>

Navigation menu