LoslegenKostenlos loslegen

Creating lists in Python

A list in Python can contain any number of elements. You generally create a list using square brackets. For example, to create a list of integers, you can use the following command:

x = [1, 2, 3]

Diese Übung ist Teil des Kurses

Introduction to Python for Finance

Kurs anzeigen

Anleitung zur Übung

  • Create a list named names containing the strings 'Apple Inc', 'Coca-Cola', and 'Walmart', in that order.
  • Print names.
  • Create a list named prices containing the price of each stock, $159.54, $37.13, and $71.17, in that order.
  • Print prices.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Create and print list names
names = ____
____

# Create and print list prices
prices = ____
____
Code bearbeiten und ausführen