MulaiMulai sekarang secara gratis

Creating a tuple

As you build your recipe scaler, you may need to convert between units. Let's say you need to store standard conversion factors that should never change (like cups to milliliters: 1 cup = 240 ml). A great way to store this is using tuples to represent the conversion pair. Tuples are perfect for this because they're immutable - conversion factors won't accidentally change during calculations.

Latihan ini adalah bagian dari kursus

Introduction to Python for Developers

Lihat Kursus

Petunjuk latihan

  • Create a tuple called cup_conversion that stores the values 1 and 240.
  • Check the type of cup_conversion.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create a tuple
cup_conversion = ____

# Check the type
print(____)
Edit dan Jalankan Kode