lstrip/rstrip 和 removeprefix/removesuffix(Python 3.9)
最近在项目中遇到个问题,想把'user:user1'这个字符串的前缀user:删除掉,留取后面的user1,代码中使用了lstrip方法(用的是python2.7)。但是测试发现:print 'user:user1'.lstrip('user:')'1'于是仔细查看了lstrip的文档说明:Return a copy of the string with leading characters removed. The chars argument is a string specifyi
原创
2022-05-07 10:52:49 ·
1084 阅读 ·
0 评论