Changes

Jump to: navigation, search

OPS435 Online Lab1

1,834 bytes added, 21:10, 12 May 2020
Part I - Interactive (leaning) mode: using the Python Interactive Shell
</source>
:* Please note that the prompt changed from '''>>>''' to '''help>'''. Try the suggestion and feel free to explore the interactive help utility. Simple press the '''Enter''' key to get out of the interactive help utility.
:* At the '''>>>''' prompt, type '''dir()''' to call the built-in function '''dir''' without function argument to display a list of data object names known to the Python interpreter at the moment. You should get a list similar to the following: <source>
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'x']
>>>
</source>
:* We are interested in the '''object''' named '''__builtins__'''. We can ask the Python interpreter to tell use more about the '''__builtins__''' by passing '''__builtins''' as a function argument to the '''dir()''' function: <source>
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError',
...
ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__',
'__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any',
'ascii', 'bin', 'bool', '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']
</source>
:* The above output shows a list of the so-called '''built-in run-time error codes''' and '''bulit-in functions'''. We are going to learn how to use them effective to save our coding effort when writing Python programs/scripts.
:* Let start with the '''print''' function.
=== Part II - Script (execution) mode: creating Python script ===
1,760
edits

Navigation menu