3.WAP TO PERFORM ALL THE FUNCTIONS AND METHODS IN STRING,LIST,TUPLE,DICTIONARY & SET.
print("=== STRING METHODS AND FUNCTIONS ===")
s = " Hello, World! "
print("Original:", repr(s))
print("Lower:", s.lower())
print("Upper:", s.upper())
print("Title:", s.title())
print("Swapcase:", s.swapcase())
print("Strip:", s.strip())
print("Lstrip:", s.lstrip())
print("Rstrip:", s.rstrip())
print("Find 'World':", s.find("World"))
print("Index of 'World':", s.index("World"))
print("Replace 'World' with 'Python':", s.replace("World", "Python"))
print("Count 'l':", s.count("l"))
print("Is Alpha:", s.isalpha())
print("Is Digit:", s.isdigit())
print("Is Alnum:", s.isalnum())
print("Is Lower:", s.islower())
print("Is Upper:", s.isupper())
print("Is Space:", s.isspace())
print("Is Title:", s.istitle())
print("Split:", s.split())
print("Join:", "-".join(["A", "B", "C"]))
print("Zfill:", "42".zfill(5))
print("Startswith ' He':", s.startswith(" He"))
print("Endswith '! ':", s.endswith("! "))
print("\n")
print("=== LIST METHODS AND FUNCTIONS ===")
lst = [1, 2, 3, 4, 5]
print("Original List:", lst)
lst.append(6)
print("Append 6:", lst)
lst.extend([7, 8])
print("Extend:", lst)
lst.insert(0, 0)
print("Insert at index 0:", lst)
lst.remove(4)
print("Remove 4:", lst)
print("Pop index 2:", lst.pop(2))
print("Index of 5:", lst.index(5))
print("Count of 2:", lst.count(2))
lst.sort()
print("Sorted:", lst)
lst.reverse()
print("Reversed:", lst)
copy_lst = lst.copy()
print("Copy:", copy_lst)
lst.clear()
print("Cleared:", lst)
print("\n")
print("=== TUPLE METHODS AND FUNCTIONS ===")
tup = (1, 2, 2, 3, 4)
print("Original Tuple:", tup)
print("Count of 2:", tup.count(2))
print("Index of 3:", tup.index(3))
print("First element:", tup[0])
print("Slicing:", tup[1:4])
print("\n")
print("=== DICTIONARY METHODS AND FUNCTIONS ===")
d = {"name": "Alice", "age": 25, "city": "New York"}
print("Original Dictionary:", d)
print("Name:", d["name"])
print("Get age:", d.get("age"))
d["email"] = "alice@example.com"
print("Added email:", d)
d.update({"age": 26})
print("Updated age:", d)
print("Pop 'city':", d.pop("city"))
print("Popitem:", d.popitem())
print("Keys:", d.keys())
print("Values:", d.values())
print("Items:", d.items())
d_copy = d.copy()
print("Copy:", d_copy)
d.clear()
print("Cleared:", d)
print("\n")
print("=== SET METHODS AND FUNCTIONS ===")
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
print("Set A:", a)
print("Set B:", b)
a.add(10)
print("Add 10:", a)
a.remove(2)
print("Remove 2:", a)
a.discard(100) # No error if not present
print("Discard 100 (no error):", a)
print("Union:", a.union(b))
print("Intersection:", a.intersection(b))
print("Difference:", a.difference(b))
print("Symmetric Difference:", a.symmetric_difference(b))
print("Is Subset:", {1, 3}.issubset(a))
print("Is Superset:", a.issuperset({1}))
print("Is Disjoint:", a.isdisjoint({100, 200}))
copy_set = a.copy()
print("Copy:", copy_set)
a.clear()
print("Cleared:", a)
print("\n")
print("=== COMMON BUILT-IN FUNCTIONS ===")
print("Length of 'Hello':", len("Hello"))
print("Type of [1,2,3]:", type([1, 2, 3]))
print("Max of [1,3,2]:", max([1, 3, 2]))
print("Min of [1,3,2]:", min([1, 3, 2]))
print("Sum of [1,2,3]:", sum([1, 2, 3]))
print("Sorted [3,1,2]:", sorted([3, 1, 2]))
print("Reversed [1,2,3]:", list(reversed([1, 2, 3])))
OUTPUT: