是否有使用方法修改python变量的快捷方式? [英] Is there a good shortcut for modifying python variables using methods?

查看:65
本文介绍了是否有使用方法修改python变量的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i += 1代替i = i + 1.

string = string.replace(...)是否有类似的缩写?

Is there a similar shorthand for string = string.replace(...)?

推荐答案

否,因为没有内置语法.

No, because there is no built-in syntax for this.

对于字符串,您仍然可以使用+=:

For a string, you can still use +=:

>>> x = "hello"
>>> x += " world"
>>> x
'hello world'

因为+ =是为字符串定义的.只是没有可替换的赋值运算符.

Because += is defined for strings. There just isn't an assignment operator for replace.

这篇关于是否有使用方法修改python变量的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆