What\'s New in Python 3.9

(kamelia khammar) #1

which is eite dash. Now you have a new method in Python
three point nine that is called clean prefix and then clean
suffix. Now I'm going to show off how to clean prefix
works. So my goal in that case will be to clean the IP
dash for every word in the items. Now, normally you
would go with something like the following. So we will
iterate over our items and I will search for something
like if item that starts with and then we will right here
eite dash. So I'm checking if the item string starts with
that prefix. And if it is, then I'm going to use a new
variable here and call it item replaced. So I will make
that we go to item not replace and then I will replace
this eite dash with an empty string and then once I go
ahead and try to print the item replaced variable, then I
will probably get the result. Now you can also do that
with string indexing, but I am showing you the two old
fashioned ways that you can do that. Now, besides all
those lines, you can go with something like item that
remove prefix and then put in as the argument, the
prefix that you want to delete.So I'm going to make that
to be equal to item without prefix, something like that.
You can use a shortened variable name for this, but I'm
just doing that. For example, reasons, and I'm going to
print the item without critics, and once I go ahead and
print the results, you'll see that there are the same so
you can use the remove prefix for these kind of reasons.
And if we want to use the remove suffix, this will be the
same behavior as well. So let me clean everything here
and paste new code that will deal with suffix deletion.

Free download pdf