Changes

Jump to: navigation, search

OPS435 Python Lab 4

70 bytes added, 13:10, 20 June 2017
PART 1 - Strings and Substrings
first_word
print(first_word)
</source>:#The index that is used inside of lists is also used to access characters in within a string. Take a step back from lists for nowFor pratice, let's create a new string, and start accessing the strings index.<br><br>:#Perform the following:<source>
course_name = 'Open System Automation'
course_code = 'OPS435'
str(course_number)[0] # Turn the integer into a string, return first character in that string
course_code[0] + course_code[1] + course_code[2]
</source>:#While a list's index is for each item in the list, a string's index is for each character in the string. In a string this is called a '''substring''', taking out a number of characters from the string and using this substring to either create a new string or display only a small portion of it<br><br>:#To demonstrate, issue the following:<source>
course_name[0:4] # This will return the first four characters NOT including index 4 -> indexes 0,1,2,3 -> but not index 4
first_word = course_name[0:4] # Save this substring for later use
13,420
edits

Navigation menu