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
Listas
Los listas son muy similares a los arrays. Pueden contener cualquier tipo de variable, y pueden contener tantas variables como desees. Las listas también se pueden iterar de una manera muy simple. Aquí hay un ejemplo de cómo construir una lista.
Acceder a un índice que no existe genera una excepción (un error).
Exercise
En este ejercicio, necesitarás agregar números y cadenas a las listas correctas usando el método "append" de listas. Debes agregar los números 1, 2 y 3 a la lista "numbers", y las palabras 'hello' y 'world' a la variable strings.
También tendrás que completar la variable second_name con el segundo nombre en la lista names, usando el operador de corchetes []
. Ten en cuenta que el índice es basado en cero, por lo que si quieres acceder al segundo elemento en la lista, su índice será 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!
