Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to delete the 1 and 2 characters at the beginning and end of python

Shulou Source: shulou.com Published: 2022-05-31 11:13:58 10月02日 Update

This article introduces the knowledge of "how to delete the 1 and 2 characters at the beginning and end of python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Specific steps for use:

1. First open the python editor and create a new python project.

2. Define a string in the python project.

Str = '1a2b12c21'

3. Use the strip method to delete the 1 and 2 characters at the beginning and end.

Str.strip ('12') # remove the 1 and 2 from the head and tail

Return the result:

'a2b12c'

Related sample code:

> str ='ab cd'

> str

'ab cd'

> str.strip () # Delete the leading and trailing spaces

'ab cd'

> str.lstrip () # Delete the opening space

'ab cd'

> str.rstrip () # Delete the trailing space

'ab cd'

This is the end of the introduction to "how to delete the 1 and 2 characters at the beginning and end of python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Head and tail character space content more knowledge project practical learned next code dilemma string actual beginning situation article method case step Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Xiaomi vpn MySQL