Changes

Jump to: navigation, search

OPS435 Python Lab 4

40 bytes added, 19:21, 21 June 2017
PART 2 - String Formatting
print('This is displaying a string by default: {0}'.format(course_number))
</source>Next, let's place a list inside the format() function and access the values, there are two ways to use the list.<br><br>
:#Let's demonstrate a range of alternative methods of printing a list by issuing the following:<source>
list1 = [1,2,3,4,5] # This is a list of numbers
print('{0[0]} {0[1]} {0[2]} {0[3]} {0[4]}'.format(list1)) # Access the values of the list using indexes via {position[index]}
print('{0} {1} {2} {3} {4}'.format(*list1)) # Expand the list into multiple positional arguments
print('{} {} {} {} {}'.format(*list1)) # Expand the list into multiple positional arguments
13,420
edits

Navigation menu