Home >Backend Development >Python Tutorial >Python intercepts and takes out part of the string
The following is obtained by split interception
>>> str = 'http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb-0-7a05a56f0b91.pdf' >>> print str.split() ['http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb-0-7a05a56f0b91.pdf'] >>> print str.split('/') ['http:', '', 'manualfile.s3.amazonaws.com', 'pdf', 'gti-chis-1-user-9fb-0-7a05a56f0b91.pdf'] >>> print str.split('/')[-1] gti-chis-1-user-9fb-0-7a05a56f0b91.pdf >>> print str.split('/')[-1].split('.')[0] gti-chis-1-user-9fb-0-7a05a56f0b91 >>>
The following is obtained by slicing
name = str[str.rfind("/")+1:str.rfind(".")]
The result is the same as above.
If we find other methods, we will continue to add them.
The above python interception method to extract part of the string is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more python interception and taking out part of the string related articles, please pay attention to the PHP Chinese website!