3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] Python Type "help", "copyright", "credits" or "license" for more information. dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] dir(str) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] # String methods help Type help() for interactive help, or help(object) for help about object. help(str.upper) Help on method_descriptor: upper(self, /) Return a copy of the string converted to uppercase. 'cat'.upper() 'CAT' s = 'cat' s.upper() 'CAT' upper(s) Traceback (most recent call last): Python Shell, prompt 9, line 1 builtins.NameError: name 'upper' is not defined # Methods are called differently than functions # value.method() wish = 'Happy Birthday' help(str.swapcase) Help on method_descriptor: swapcase(self, /) Convert uppercase characters to lowercase and lowercase characters to uppercase. wish.swapcase() 'hAPPY bIRTHDAY' wish.swapcase # don't forget to call it with the () help(str.isupper) Help on method_descriptor: isupper(self, /) Return True if the string is an uppercase string, False otherwise. A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string. "R2D2".isupper() True "R2d2".isupper() False help(str.isalnum) Help on method_descriptor: isalnum(self, /) Return True if the string is an alpha-numeric string, False otherwise. A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string. "R2D2".isalnum() True "R2D2!".isalnum() False help(str.isalpha) Help on method_descriptor: isalpha(self, /) Return True if the string is an alphabetic string, False otherwise. A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string. "R2D2".isalpha() False s = 'cats are important in education' help(str.find) Help on method_descriptor: find(...) S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. s 'cats are important in education' s.find('cat') 0 # we fist find the substring 'cat' at index 0 s.find('cat', 1) 25 s[25] 'c' s[25:28] 'cat' s.find('tsn') -1 # how do we always find the second time the substring appears s.find('cat', s.find('cat') + 1) 25 s.find('cat') + 1 1 msg = """jazz is the best""" msg 'jazz is\nthe best' print(msg) jazz is the best msg = 'i like\n\n\n\n\njazz' msg 'i like\n\n\n\n\njazz' print(msg) i like jazz # Worksheet wish = 'Happy Birthday' wish[0].lower() + wish[6].lower() 'hb' wish.swapcase() 'hAPPY bIRTHDAY' wish[0].lower() + wish[1:6] + wish[6].lower() + wish[7:] 'happy birthday' wish.lower() 'happy birthday' robot = 'R2D2' robot.isupper() True robot.isalpha() False robot.isalnum() True robot.isdigit() False help(str.isdigit) Help on method_descriptor: isdigit(self, /) Return True if the string is a digit string, False otherwise. A string is a digit string if all characters in the string are digits and there is at least one character in the string. lyrics = """O Canada! Our home and native land! True patriot love in all thy sons commands.""" lyrics.find('!') 8 lyrics.find('!').find('!') Traceback (most recent call last): Python Shell, prompt 57, line 1 builtins.AttributeError: 'int' object has no attribute 'find' lyrics.find('!', lyrics.find('!')) 8 lyrics.find('!', 8) 8 lyrics.find('!', lyrics.find('!') + 1) 34