CSE 101 Lecture Notes - Lecture 13: String Operations, Ebay, Delimiter
Document Summary
Virtually every programming language has at least some minimal built-in capabilities for working with strings. A string is a sequence of 0 or more characters. Use the len() function to get the number of characters in a string i. e. phase = cse 101 is fun! phraselen = len(phrase) # phraselen is 15. Use the in operator to test whether one string contains another string i. e. result = rook in stony brook print( result is + str(result)) You are most likely to use the in operator as part of a selection or other conditional execution: directions = turn left at smith st. if left in directions: print( turning left ) We can access individual characters in a string using a character"s index (position) Indices start with 0 str[3] returns the 4 th character in str. Negative indices start counting from the end (-1 is the last character) So str[-1] and str[len(str)-1] would both give us the final character in the string.