Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/marioaje/Python/llms.txt

Use this file to discover all available pages before exploring further.

So far in the course every variable has held a single value. Lists change that — a list is an ordered collection that can hold as many values as you need, all under one variable name. You can read individual items by their position, add new items to the end, and remove items you no longer need, all with built-in Python syntax. This page also covers the three main ways to format output with print(), which you will use constantly as you build programs.

Section 1 — Lists

Creating a List

A list is written with square brackets [], and its items are separated by commas. The list below — taken directly from the course — mixes strings, an integer, a float, and a boolean all in the same collection:
Python lists can hold values of different types at the same time. A single list can contain strings, integers, floats, and booleans side by side — there is no requirement that all items share the same type.
semana1/listadedatos.py
mylista = ['mario', "Jimenez", 44, 10.1, True]
#            0    ,     1    ,  2,   3  ,  4
print(mylista)

Index Reference

Each item in the list occupies a numbered index, starting at 0:
IndexValueType
0'mario'str
1"Jimenez"str
244int
310.1float
4Truebool

Reading and Updating Items

Pass the index inside square brackets to read or overwrite any item:
semana1/listadedatos.py
print( mylista[1])                      # Jimenez
mylista[1] = input("Ingrese el valor: ") # overwrite index 1 with user input
print( mylista[0], mylista[1])           # mario <new value>
print(mylista)

Adding and Removing Items

semana1/listadedatos.py
mylista.append('Vivo en Costa Rica')  # adds item to the END of the list
print(mylista)

mylista.pop()                          # removes the LAST item
print(mylista)

.append(value)

Adds value to the end of the list. The list grows by one element.

.pop()

Removes and returns the last element. The list shrinks by one element.

Full Program

Here is the complete listadedatos.py as a single runnable block:
semana1/listadedatos.py
mylista = ['mario', "Jimenez", 44, 10.1, True]
#            0    ,     1    ,  2,   3  ,  4
print(mylista)

print( mylista[1])
mylista[1] = input("Ingrese el valor: ")
print( mylista[0], mylista[1])
print(mylista)

mylista.append('Vivo en Costa Rica')
print(mylista)

mylista.pop()
print(mylista)

Section 2 — Print Formatting

The course file personalizacionprint.py demonstrates three different ways to combine variables into a single line of output. All three approaches produce a readable result — understanding when to use each one makes your code cleaner.
semana1/personalizacionprint.py
valora = input("Ingrese su texto: ")
valorb = input("Su nombre: ")

print ( valora + "\"-\"" + valorb)
print ( valora + ' ' + valorb)
print ( valora, valorb)
# Join strings by placing + between them.
# Any literal text must also be a string in quotes.
print( valora + "\"-\"" + valorb)
# Output example: Hello"-"Mario

When to Use Each Approach

ApproachBest when…
+ concatenationYou need precise control over separators or special characters between values
+ ' ' + spaceYou want a simple space and are working with strings only
print(a, b, ...)You have multiple values and want Python to handle spacing automatically — also works with non-string types without needing explicit conversion
The + operator requires both sides to be strings. If you try to concatenate a string and an integer with + you will get a TypeError. Using multiple comma-separated arguments to print() avoids this — Python converts each argument to a string automatically before printing.

Build docs developers (and LLMs) love