nattyjojo Posted March 13, 2022 Share Posted March 13, 2022 I recently started learning Coding IN PYTHON, i have Exercises i still don't understand and i would appreciate if any one can give correct answers, with explanation, and details to my questions in a way a NEWBIE can understand. Link to comment Share on other sites More sharing options...
nattyjojo Posted March 13, 2022 Author Share Posted March 13, 2022 txt = "Hello, And Welcome To My World!" x = txt.casefold() print(x) txt = "Hello, And Welcome To My World!" y = txt.lower() print(y) What's the difference between function casefold() and .lower ? Python Tutorial link Link to comment Share on other sites More sharing options...
nattyjojo Posted March 13, 2022 Author Share Posted March 13, 2022 is there a default to .insert new data to existing list ? Example: thislist = ["apple", "banana", "cherry"] thislist.insert(2, "watermelon") #i used 2 as index and passed watermelon as new data to list and it will take position of cherry print(thislist) it returns error when i try it this way : thislist = ["apple", "banana", "cherry"] thislist.insert(, "watermelon") print(thislist) Link to comment Share on other sites More sharing options...
Ingolme Posted March 14, 2022 Share Posted March 14, 2022 10 hours ago, nattyjojo said: txt = "Hello, And Welcome To My World!" x = txt.casefold() print(x) txt = "Hello, And Welcome To My World!" y = txt.lower() print(y) What's the difference between function casefold() and .lower ? Python Tutorial link It's complicated. Here's an excerpt from the Python manual: https://docs.python.org/3/library/stdtypes.html#str.casefold Quote Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string. For example, the German lowercase letter 'ß' is equivalent to "ss". Since it is already lowercase, lower() would do nothing to 'ß'; casefold() converts it to "ss". 10 hours ago, nattyjojo said: is there a default to .insert new data to existing list ? Example: thislist = ["apple", "banana", "cherry"] thislist.insert(2, "watermelon") #i used 2 as index and passed watermelon as new data to list and it will take position of cherry print(thislist) it returns error when i try it this way : thislist = ["apple", "banana", "cherry"] thislist.insert(, "watermelon") print(thislist) If you want to add an element to a list, use the append() method. insert() is for when you want to insert an element at a specific position. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now