Changes

Jump to: navigation, search

OPS435 Python Lab 4

117 bytes added, 09:19, 21 June 2017
PART 1 - Strings and Substrings
:#If a string contains many values separated by a single character, such as a space, the string can be split on those values and create a list of values<source>
lower_name.split(' ') # Provide the split() function with a character to split on
</source>:#The above example will return a list of strings, which we can access just like all of lists. :#Let's practice more string manipulation by issuing the following:<source>
list_of_strings = lower_name.split(' ') # Split string on spaces and store the list in a variable
list_of_strings # Display list
list_of_strings[0] # Display first item in list
</source>:#Since this list is lists are actually a list of '''strings''', you should be able to use any function that works with a string on strings will work on items in a list.:#To demonstrate, issue the listfollowing:<source>
list_of_strings[0].upper() # Use the functmon after the index to interact with just a single string in the list
first_word = list_of_strings[0]
13,420
edits

Navigation menu