首页 > 解决方案 > 当第三个 str.replace() 参数为负时会发生什么?

问题描述

请解释这里发生了什么?

print("banana".replace('a','1',-3))

输出是: b1n1n1

标签: pythonpython-3.xreplacestr-replace

解决方案


根据票 5416

负值在某种程度上被用作标记值来表示全部替换。


推荐阅读