CMPT 120 Lecture Notes - Lecture 11: Peter Jackson
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
Lecture 11: strings, lists, and control structures: while. >>> sentence = my name is peter robert jackson! split() function is used to parse or break a long string into words or parts. >>> words = "my name is peter robert jackson! 5 print(words) len(words) print(words[3]) words = ["my", "name", "is", "peter", "robert", "jackson!"] The variable words in this case refer to group of values (i. e. , not a single value. ) So, the split() function creates a list. List: is an object that contains multiple data items. Values in a list can be accessed using an index. By default, the split method uses spaces as separators (that is, it returns a list of the words in the string that are separated by spaces). You can specify a different separator by passing it as an argument.