Posts

  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"))
1. Basic Data Types, Operators, Expressions, and Input/Output # Basic Data Types a = 10        # integer b = 3.5       # float c = "Hello"   # string d = True      # boolean # Operators and Expressions sum_result = a + b product = a * b # Input and Output name = input("Enter your name: ") print("Hello,", name) print("Sum is:", sum_result) print("Product is:", product) 2. Strings and Conditional Statements # Strings text = "Python is fun" print(text.upper()) # converts to uppercase print(text.lower()) # converts to lowercase # Conditional Statements age = int(input("Enter your age: ")) if age >= 18:     print("You are an adult.") else:     print("You are a minor.") 3. Lists and Tuples Using Built-in Functions # List fruits = ["apple", "banana", "cherry"] fruits.append("orange") # adding an element print(fruits) print(len(fruits)) # number of e...