Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 4

1 byte added, 09:53, 21 June 2017
PART 1 - Strings and Substrings
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>You can use a technique that uses index numbers of a string to '''cut-out''' or '''"parse"''' smaller portions of text within a string. This term is referred to as a '''substring'''. We can use this to 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
13,420
edits