32 lines
735 B
Markdown
32 lines
735 B
Markdown
---
|
|
title: input()
|
|
tags:
|
|
- python
|
|
- functions
|
|
- input
|
|
aliases:
|
|
- input
|
|
- input-function
|
|
- user-input
|
|
---
|
|
|
|
> [!note] Concept
|
|
> The `input()` function waits for the user to type text and press `ENTER`, then returns it as a string.
|
|
>
|
|
> > [!example] Example
|
|
> > ```python
|
|
> > myName = input()
|
|
> > ```
|
|
> > If the user types `Al`, the result is equivalent to:
|
|
> > ```python
|
|
> > myName = 'Al'
|
|
> > ```
|
|
>
|
|
> > [!important] Best Practices
|
|
> > - Always assume `input()` returns a string — cast with `int()`, `float()`, etc. if needed.
|
|
> > - Only use `input()` in Python 3. In Python 2, use `raw_input()` instead.
|
|
>
|
|
> > [!info] Related Notes
|
|
> > [[typeConversions]]
|
|
> > [[functions]]
|
|
> > [[pythonSyntaxOverview]]
|