''' Minimum 10 Methods of String 1. join() ''' myTuple = ("Rahul", "Pankaj", "Shyam") x = "->".join(myTuple) print(x) ''' 2. find() ''' variable = "India is my country and all Indians are my brthers and sisters." x = variable.find("my") print(x) ''' 3. format() ''' txt = "Sale for only {price:.2f} Rupees:)" print(txt.format(price = 49)) ''' 4. title(): Make the first letter in each word upper case ''' text = "This is a sentence whose first letter will capitalize." x = text.title() print(x) ''' 5. upper(): Upper case the string ''' text2 = "This is a sentence whose all letters will capitalize." x = text2.upper() print(x) ''' 6. translate():Replace any "S" characters with a "P" character ''' mydict = {83: 80} txt = "Hello Sunny!" print(txt.translate(mydict)) ''' 7. strip():Remove spaces at the beginning and at the end of the string: ''' text3 = " Tomato_is_a_fruit " x = text3.strip() print(x) ''' 8. swapcase():Make the lower case letters upper case and the upper case letters lower case: ''' text4 = "Hello My Name Is GAJENDRA" x = text4.swapcase() print(x) ''' 9. replace():Replace the word FROM word1 TO word2: ''' text5 = "I like bananas" x = text5.replace("bananas", "apples") print(x) ''' 10. lower():Lower case the whole string: ''' text6 = "Hello my FRIENDS" x = text6.lower() print(x) ''' Minimum 10 Methods of List 1. append(): Add an element to the fruits list: ''' fruits = ['apple', 'banana', 'cherry'] fruits.append("orange") print(fruits) ''' 2. clear(): Remove all elements from the fruits list: ''' fruits2 = ['apple', 'banana', 'cherry', 'orange'] fruits2.clear() print(fruits2) ''' 3. copy(): Copy the list: ''' fruits3 = ['apple', 'banana', 'cherry', 'orange'] x = fruits3.copy() print(x) ''' 4. count(): Return the number of times the value "cherry" appears in the fruits list: ''' fruits4 = ['apple', 'banana', 'cherry', 'apple'] x = fruits4.count("apple") print(x) ''' 5. extend(): Add the elements of cars to the fruits list: ''' fruits5 = ['apple', 'banana', 'cherry'] cars = ['Ford', 'BMW', 'Volvo'] fruits5.extend(cars) print(fruits5) ''' 6. index(): What is the position of the value "cherry": ''' fruits6 = ['apple', 'banana', 'cherry'] x = fruits6.index("cherry") print(x) ''' 7. insert(): Insert the value "orange" as the second element of the fruit list: ''' fruits7 = ['apple', 'banana', 'cherry'] fruits7.insert(1, "orange") print(fruits7) ''' 8. pop(): Remove the defined element of the fruit list: ''' fruits8 = ['apple', 'banana', 'cherry'] fruits8.pop(1) print(fruits8) ''' 9. reverse(): Reverse the order of the fruit list: ''' fruits9 = ['apple', 'banana', 'cherry'] fruits9.reverse() print(fruits9) ''' 10. sort(): Sort the list alphabetically: ''' cars = ['Ford', 'BMW', 'Volvo'] cars.sort() print(cars) ''' Methods of Tuple 1. count():Return the number of times the value 5 appears in the tuple: ''' thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) x = thistuple.count(5) print(x) ''' 2. index(): Search for the first occurrence of the value 8, and return its position: ''' thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5) x = thistuple.index(8) print(x) ''' Methods of Dictionary 1. clear():Removes all the elements from the dictionary: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.clear() print(car) ''' 2. copy():Returns a copy of the dictionary: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.copy() print(x) ''' 3. fromkeys():Returns a dictionary with the specified keys and value: ''' x = ('key1', 'key2', 'key3') y = 0 thisdict = dict.fromkeys(x, y) print(thisdict) ''' 4. get():Returns the value of the specified key: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.get("model") print(x) ''' 5. items():Return the dictionary's key-value pairs: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.items() print(x) ''' 6. keys():Returns a list containing the dictionary's keys: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.keys() print(x) ''' 7. pop():Removes the element with the specified key: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.pop("model") print(car) ''' 8. setdefault():Returns the value of the specified key. If the key does not exist: insert the key, with the specified value: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.setdefault("model", "Bronco") print(x) ''' 9. update():Updates the dictionary with the specified key-value pairs: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.update({"color": "White"}) print(car) ''' 10. values():Returns a list of all the values in the dictionary: ''' car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.values() print(x) ''' Q-2. Difference between different types of copy functions in Python. ''' ''' A copy is sometimes needed so one can change one copy without changing the other. In Python, there are two ways to create copies : 1- Deep copy: Deep copy is a process in which the copying process occurs recursively. It means first constructing a new collection object and then recursively populating it with copies of the child objects found in the original. In case of deep copy, a copy of object is copied in other object. It means that any changes made to a copy of object do not reflect in the original object. In python, this is implemented using “deepcopy()” function. 2- Shallow copy: A shallow copy means constructing a new collection object and then populating it with references to the child objects found in the original. The copying process does not recurse and therefore won’t create copies of the child objects themselves. In case of shallow copy, a reference of object is copied in other object. It means that any changes made to a copy of object do reflect in the original object. In python, this is implemented using “copy()” function. '''