voidex/20-29 Areas/20 Programming/20.01 Python/input().md

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]]