Jump to content

PYTHON'S NEWBIE'S QESTIONS


nattyjojo

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...