pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pythonitalia/python-abc/blob/master/docs/Pyllole/25_Input.md

assets.com/assets/global-0bd78641c0a1f3e0.css" /> python-abc/docs/Pyllole/25_Input.md at master · pythonitalia/python-abc · GitHub
Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.5 KB

File metadata and controls

38 lines (26 loc) · 1.5 KB

Input

La funzione input() permette di interagire con la console e fornire dei dati, tramite tastiera, al programma.

L'argomento passato alla funzione input(prompt) è la stringa che viene mostrata sulla console in attesa dell'inserimento dei dati.

>>> input("Inserisci la tua età: ")
Inserisci la tua età: 

Il programma resterà in attesa dell'inserimento di un dato finché non verrà premuto il tasto invio.

La funzione restituisce ciò che è stato inserito tramite tastiera.

>>> age=input("Inserisci la tua età: ")
Inserisci la tua età: 42
>>> print(age)
42

Valore restituito

La funzione input() restituisce sempre una stringa, se si vuole utilizzare il risultato come dato numerico è necessario convertirlo utilizzando le funzioni int() o float().

>>> stringa = input("Inserisci un numero intero: ")
Inserisci un numero intero: 42
>>> numero=int(stringa)

Importante: se la stringa passata a int() non è convertibile in un intero, Python genererà un'errore, è quindi consigliabile gestire l'eccezione con try/except

Nota: nelle versioni 2.x l'attuale funzione input() si chiamava raw_input(). La funzione input() di Python2 esiste ma ha un comportamento differente da quello qui descritto.

Vedi l'esempio pratico nella pagina try/except per come gestire l'errata conversione.

Vedi l'esempio pratico nella pagina cicli per come ripetere input() finché il valore è corretto.

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy