Sample Progs
Sample Progs
Lists
Example:
Python
my_list = [1, 2, 3, "hello", True]
Tuples
Example:
Python
my_tuple = (1, 2, 3, "hello", True)
Sets
Example:
Python
my_set = {1, 2, 3, "hello"}
Dictionaries
Example:
Python
my_dict = {"name": "Alice", "age": 30, "city": "New York"}
Lists: Use when you need an ordered collection of elements that can be modified.
Tuples: Use when you need an ordered collection of elements that should not be modified.
2
Sets: Use when you need a collection of unique elements without preserving order.
Dictionaries: Use when you need to store key-value pairs.
Python
# List of fruits
fruits = ["apple", "banana", "orange"]
# Tuple of colors
colors = ("red", "green", "blue")
# Set of numbers
numbers = {1, 2, 3, 4, 5}
# Modify elements
fruits[1] = "grape"
print(fruits) # Output: ['apple', 'grape', 'orange']
# Append an element
fruits.append("mango")
print(fruits) # Output: ['apple', 'grape', 'orange', 'mango']
num1 = 15
num2 = 12
# printing values
if a <= b:
return a
else:
return b
# Driver code
a=2
b=4
print(minimum(a, b))
a=2
b=4
minimum = min(a, b)
print(minimum)
# list of numbers
list1 = [11, -21, 0, 45, 66, -93]
# checking condition
if num < 0:
print(num, end=" ")
# list of numbers
list1 = [-10, 21, -4, -45, -66, 93]
num = 0
# checking condition
if list1[num] < 0:
print(list1[num], end=" ")
# increment num
num += 1
5