๐Ÿ“ ๐Ÿ”ฌ Python Lists#

๐Ÿงช Lists in Python#

Definition: Lists are ordered collections of items, defined using square brackets []. They can store:

  • Reaction parameters (e.g., temperature, pressure)

  • Concentrations of species in a reactor

  • Equipment states in a process

Example:

# List of reactor temperatures in Celsius
temperatures = [350, 400, 450, 500]
print(temperatures)
[350, 400, 450, 500]

๐Ÿ“‹ Key Features of Lists#

  1. Ordered: Items retain the sequence in which they are added.

  2. Mutable: You can change, add, or remove items.

Example: Modifying a List#

# Adding a new temperature
temperatures.append(550)
print(temperatures)
[350, 400, 450, 500, 550]

โš—๏ธ Tuples in Python#

Definition: Tuples are immutable collections, defined using parentheses (). Ideal for:

  • Fixed equipment configurations (e.g., pipe diameters)

  • Constant reaction parameters (e.g., activation energy, rate constants)

Example:

# Tuple of reaction rate constants
rate_constants = (1.2, 3.4, 2.1)
print(rate_constants)
(1.2, 3.4, 2.1)

๐Ÿ”„ Lists vs Tuples#

Feature

Lists ([])

Tuples (())

Mutability

Mutable (can change)

Immutable (cannot change)

Use Cases

Dynamic data (e.g., logs)

Fixed data (e.g., configs)

Example#

# Changing a list
temperatures[0] = 360
print(temperatures)

# Tuples are immutable
# rate_constants[0] = 2.0  # This will raise an error
[360, 400, 450, 500, 550]