Python Fundamentals Tutorial : Index
The Python installation includes an interactive interpreter that you can use to execute code as you type it. This is a great tool to use to try small samples and see the result immediately without having to manage output or print statements.
If you have not done it yet, download the lab files at the following URL: https://marakana.com/static/student-files/python_fundamentals_labs.zip
(Linux / Mac) Open a terminal and type python.
(Windows) Open the Python IDLE IDE from the Start menu.
- What is the version number?
-
Type
help(str)This is a simple way to get documentation for a builtin or standard library function. You can also use the online HTML documentation.
>>> help(str) Help on class str in module __builtin__: class str(basestring) | str(object) -> string | | Return a nice string representation of the object. | If the argument is a string, the return value is the same object. | | Method resolution order: | str | basestring | object | | Methods defined here: | | __add__(...) | x.__add__(y) <==> x+y | ...
-
Note the use of methods with names with two underscores at the beginning and end of the name. These are methods that you will generally never call directly. How do you think the
__add__()method gets executed? - Now try typing the following commands to see the output. Note that you don’t assign a result, you get that result in the interpreter.
>>> 'hello world' 'hello world' >>> _ + '!' 'hello world!' >>> hw = _ >>> hw 'hello world!'
![]() | Tip |
|---|---|
In the interactive interpreter, you can use the special variable "_" to refer to the result of the last statement. Handy in this mode, but meaningless in scripts. |
![]() | Note |
|---|---|
Throughout the rest of this courseware, the ">>>" in a listing indicates that the code is being executed in the interactive interpreter. |
![[Tip]](../images/tip.png)
![[Note]](../images/note.png)