类型“str”在Python中没有预期的属性“__setitem__”

问题描述 投票:0回答:1

当我调用静态类方法时,为什么会收到“Type 'str' does not have Expected attribute '__setitem__'”?

@staticmethod
def replace_region_decimal_sign(to_convert):
    to_convert[to_convert.index(',')] = '.'  # Replace comma ("region" decimal sign) with a dot
    return to_convert

if __name__ == "__main__":
    print(Calculator.replace_region_decimal_sign("1,23"))

python string attributes
1个回答
0
投票

为什么不使用替换?

to_convert.replace(",", ".")
© www.soinside.com 2019 - 2024. All rights reserved.