sbs5@ladybug:~/cs200/www/lectures$ date Mon Sep 9 02:26:36 PM EDT 2024 sbs5@ladybug:~/cs200/www/lectures$ pwd /home/accts/sbs5/cs200/www/lectures sbs5@ladybug:~/cs200/www/lectures$ p Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 1 = 2 File "", line 1 1 1 = 2 ^ SyntaxError: invalid syntax >>> 1 == 2 False >>> help(len) Help on built-in function len in module builtins: len(obj, /) Return the number of items in a container. >>> len('hello') 5 >>> len([1,2,3,4,5] ... ) 5 >>> help(help) Help on _Helper in module _sitebuiltins object: class _Helper(builtins.object) | Define the builtin 'help'. | | This is a wrapper around pydoc.help that provides a helpful message | when 'help' is typed at the Python interactive prompt. | | Calling help() at the Python prompt starts an interactive help session. | Calling help(thing) prints help for the python object 'thing'. | | Methods defined here: | | __call__(self, *args, **kwds) | Call self as a function. | | __repr__(self) | Return repr(self). | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) >>> dir(sys) Traceback (most recent call last): File "", line 1, in NameError: name 'sys' is not defined >>> import sys >>> dir(sys) ['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '__unraisablehook__', '_base_executable', '_clear_type_cache', '_current_exceptions', '_current_frames', '_deactivate_opcache', '_debugmallocstats', '_framework', '_getframe', '_git', '_home', '_xoptions', 'abiflags', 'addaudithook', 'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth', 'get_int_max_str_digits', 'getallocatedblocks', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'last_traceback', 'last_type', 'last_value', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'orig_argv', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'platlibdir', 'prefix', 'ps1', 'ps2', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'set_int_max_str_digits', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdlib_module_names', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info', 'warnoptions'] >>> dir(dir) ['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__'] >>> str(123) '123' >>> str(3 + 7) '10' >>> s = 'hello' >>> s 'hello' >>> s.capitalize() 'Hello' >>> s 'hello' >>> s.uppercase() Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'uppercase' >>> s.upper() 'HELLO' >>> s.upper().lower() 'hello' >>> s 'hello' >>> s.isalpha() True >>> '123'.isalpha() False >>> '123'.isnumeric() True >>> '123'.isdigit() True >>> '123'.isalnum() True >>> s 'hello' >>> s.islower() True >>> s.isupper() False >>> s = ' hello world ' >>> s ' hello world ' >>> len(s) 17 >>> s.strip() 'hello world' >>> len(s.strip()) 11 >>> s.upper() ' HELLO WORLD ' >>> s.capitalize() ' hello world ' >>> s.strip().capitalize() 'Hello world' >>> s.strip().startswith('h') True >>> s.startswith('h') False >>> s.find(' ') 0 >>> s ' hello world ' >>> s[0] ' ' >>> s ' hello world ' >>> s[3] 'h' >>> s[4] 'e' >>> s = s.strip() >>> s 'hello world' >>> s[-1] 'd' >>> s[-2] 'l' >>> s[-3] 'r' >>> len(s) 11 >>> s[11] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> s[10] 'd' >>> s[-11] 'h' >>> s[-12] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> s 'hello world' >>> s[0:4] 'hell' >>> s[0:5] 'hello' >>> s[:5] 'hello' >>> s[7:] 'orld' >>> s[6:] 'world' >>> s[:] 'hello world' >>> s[::2] 'hlowrd' >>> s[::-1] 'dlrow olleh' >>> s == s[::-1] False >>> r = 'radar' >>> r == r[::-1] True >>> r 'radar' >>> id(r) 139608444830704 >>> id(s) 139608443644592 >>> x = s >>> x 'hello world' >>> id(x) 139608443644592 >>> x = s[:] >>> x 'hello world' >>> id(x) 139608443644592 >>> id(s) 139608443644592 >>> s == x True >>> s is x True >>> s = s + 'x' >>> s 'hello worldx' >>> s == x False >>> s is x False >>> id(x) 139608443644592 >>> id(s) 139608444709488 >>> s = 'a string' >>> s.replace(' ', '*') 'a*string' >>> s 'a string' >>> s.split() ['a', 'string'] >>> a = 'every good boy does fine' >>> s.split() ['a', 'string'] >>> a.split() ['every', 'good', 'boy', 'does', 'fine'] >>> a.replace(' ','/') 'every/good/boy/does/fine' >>> aa = a.replace(' ','/') >>> aa 'every/good/boy/does/fine' >>> aa.split() ['every/good/boy/does/fine'] >>> aa.split('/') ['every', 'good', 'boy', 'does', 'fine'] >>> '***'.join(aa.split('/')) 'every***good***boy***does***fine' >>> ' '.join(aa.split('/')) 'every good boy does fine' >>> ord('a') 97 >>> ord('A') 65 >>> ord('B') 66 >>> char(97) Traceback (most recent call last): File "", line 1, in NameError: name 'char' is not defined. Did you mean: 'chr'? >>> chr(97) 'a' >>> chr(ord('7') ... ) '7' >>> l = [1,2,3,4,5] >>> len(l) 5 >>> l[0] 1 >>> l[4] 5 >>> l[-1] 5 >>> l[:3] [1, 2, 3] >>> l[3:] [4, 5] >>> l[::-1] [5, 4, 3, 2, 1] >>> l[5] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> l[-6] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> for element in l: print (element*2, end='') print (' x') print ('y') ... ... ... File "", line 4 print ('y') ^^^^^ SyntaxError: invalid syntax >>> for x in l: ... print (x * 2, x) ... 2 1 4 2 6 3 8 4 10 5 >>> l [1, 2, 3, 4, 5] >>> sum = 0 >>> for x in l: ... sum = sum + x ... >>> sum 15 >>> for x in l: ... sum += x ... >>> sum 30 >>> 3 in l True >>> l [1, 2, 3, 4, 5] >>> 6 in l False >>> 6 not in l True >>> sbs5@ladybug:~/cs200/www/lectures$ exit Process shell finished