是否可以在 Python 中转义保留字? [英] Is it possible to escape a reserved word in Python?

查看:33
本文介绍了是否可以在 Python 中转义保留字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以保留字命名变量可能不是一个好主意,但我很好奇:

It may not be a good idea to name a variable after a reserved word, but I am curious:

Python 中是否有任何转义语法允许您使用保留字作为变量名?

Is there any escape syntax in Python to allow you to use a reserved word as the name of a variable?

例如,在 C# 中,这可以通过在保留字前加上 @

For example, in C# this can be done by prefixing the reserved word with @

推荐答案

这是不可能的,但是在 Python 中附加一个 _ 以获取新标识符是某种传统:

It is not possible, however it is some kind of a tradition in Python to append a _ to get a new identifier:

def drive(from_, to):
    pass

这篇关于是否可以在 Python 中转义保留字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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