+ Python - Interactive Mode
This commit is contained in:
parent
6a308db030
commit
19a6297fce
2 changed files with 36 additions and 2 deletions
|
@ -5,5 +5,3 @@
|
|||
## Insights:
|
||||
|
||||
## References:
|
||||
|
||||
## Related Notes:
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
### What is it?
|
||||
|
||||
Interactive mode in Python is a mode where the interpreter reads commands directly from a terminal (tty). It is designed for testing and immediate execution of commands. When Python starts in this mode, it displays a welcome message that includes the version number and prompts the user for input. The interactive mode is part of the broader functionality of the Python Interpreter, which is detailed in [[Invoking the Interpreter]].
|
||||
### How to Use It:
|
||||
#### Starting Interactive Mode
|
||||
- Start Python in interactive mode by typing `python` or `python3.13` (for Python 3.13) in a terminal.
|
||||
- The interpreter prompts with `>>>` (primary prompt) for a new command or `...` (secondary prompt) for continuation lines in multi-line constructs.
|
||||
#### Example Session
|
||||
|
||||
```plaintext
|
||||
python3.13
|
||||
Python 3.13 (default, April 4 2023, 09:25:04)
|
||||
[GCC 10.2.0] on linux
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>>
|
||||
```
|
||||
#### Example of a Multi-Line Construct
|
||||
|
||||
```python
|
||||
>>> the_world_is_flat = True
|
||||
>>> if the_world_is_flat:
|
||||
... print("Be careful not to fall off!")
|
||||
...
|
||||
Be careful not to fall off!
|
||||
```
|
||||
#### Exiting Interactive Mode
|
||||
- Type `exit()` or press `Ctrl+D` (Linux/Mac) or `Ctrl+Z` (Windows) to leave interactive mode.
|
||||
### Insights:
|
||||
#### Key Features of Interactive Mode
|
||||
|
||||
1. **Primary Prompt (`>>>`)**: Used for new commands.
|
||||
2. **Secondary Prompt (`...`)**: Used for continuation lines in constructs like loops or conditionals.
|
||||
3. **Welcome Message**: Displays Python version and other information before the first prompt.
|
||||
4. **Dynamic Testing**: Ideal for quick testing and debugging small code snippets.
|
||||
### References:
|
||||
- Python Official Docs: [Interactive Mode](https://docs.python.org/3/tutorial/appendix.html#tut-interac)
|
Loading…
Reference in a new issue