2. Lists

Q3. Create a list and perform operations: add, remove, sort, reverse.


python

Copy code

my_list = [5, 3, 8, 1]

my_list.append(10) # Add

my_list.remove(3) # Remove

my_list.sort() # Sort ascending

my_list.reverse() # Reverse

print(my_list)

Q4. Find the largest and smallest number in a list.


python

Copy code

numbers = [4, 1, 7, 3, 9]

print("Max:", max(numbers))

print("Min:", min(numbers))


4. String Operations

Q7. Perform string slicing and concatenation.

s = "Python"
print(s[0:3]) # Slice first 3 letters
print(s + " Programming") # Concatenate

Q8. Find length, uppercase, lowercase, and replace characters.

text = "Hello World" print(len(text)) print(text.upper()) print(text.lower()) print(text.replace("World", "Python"))






Comments

Popular posts from this blog