Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!

This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join 11 million other learners and get started learning Python for data science today!

Good news! You can save 25% off your Datacamp annual subscription with the code LEARNPYTHON23ALE25 - Click here to redeem your discount

Liste


I list sono molto simili agli array. Possono contenere qualsiasi tipo di variabile e possono contenere quante variabili desideri. I list possono anche essere iterati in modo molto semplice. Ecco un esempio di come costruire un list.

Accedere a un indice che non esiste genera un'eccezione (un errore).

Exercise

In questo esercizio, dovrai aggiungere numeri e stringhe alle liste corrette utilizzando il metodo "append" del list. Devi aggiungere i numeri 1, 2 e 3 alla lista "numbers", e le parole 'hello' e 'world' alla variabile strings.

Dovrai anche riempire la variabile second_name con il secondo nome nella lista names, utilizzando l'operatore delle parentesi []. Nota che l'indice è basato su zero, quindi se vuoi accedere al secondo elemento nella lista, il suo indice sarà 1.

This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

Previous Tutorial Next Tutorial Take the Test
Copyright © learnpython.org. Read our Terms of Use and Privacy Policy