I have the following code:
url = "abcdc.com" print(url.strip(".com"))
Now I do
Is there a better way?
strip doesn"t mean "remove this substring".
y as a set of characters and strips any characters in that set from both ends of
url = "abcdc.com" url.removesuffix(".com") # Returns "abcdc" url.removeprefix("abcdc.") # Returns "com"
The relevant Python Enhancement Proposal is PEP-616.
On Python 3.8 and older you can use
endswith and slicing:
url = "abcdc.com" if url.endswith(".com"): url = url[:-4]
Or a regular expression:
import re url = "abcdc.com" url = re.sub(".com$", "", url)
Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information (TM), 2nd Edition. Execute Data Quality Projects, Second Edition presents a structured yet flexible approach to cr...
Python Crash Course is the world's best-selling guide to the Python programming language. This quick and in-depth introduction to Python programming will get you started writing programs, solving prob...
The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition). The Pragmatic Programmer is one of those rare technical books that you will read, reread, and re-read over...
The Apache Hadoop software library has come into it’s own. It is the basis for advanced distributed development for a host of companies, government institutions, and scientific research facilities. ...