Q1
What is the difference between a List and a Tuple?
💬Answer
- List (
[]): Mutable (can be modified after creation). - Tuple (
()): Immutable (cannot be changed once created). - DevOps Use Case: Use a list for dynamic data (e.g., list of IPs retrieved from AWS API that you need to filter). Use a tuple for fixed data (e.g., a hardcoded set of allowed HTTP response codes
(200, 201, 204)).
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
my_list[0] = 10 # Works
# my_tuple[0] = 10 # Raises TypeError
Related Python Questions
View All PythonQuestions →
Created by
Apurv Gujjar
DevOps & Cloud Engineer
Specialized in:DevOpsAWSGCPKubernetesTerraformDocker
View Portfolio