python - 如果太长,是否可以剪切长变量名?
问题描述
我有一个很长的命名变量,是否可以将其剪切,例如一半?
aquiredCostsOfIncomeInSamePlaceOfLiveAndWorkPersonUnderTwentySixNotAStudent = 250
我已经尝试过,但它不起作用:
反斜杠:
aquiredCostsOfIncomeInSamePlaceOf\ LiveAndWorkPersonUnderTwentySixNotAStudent = 250
反斜杠和括号:
(aquiredCostsOfIncomeInSamePlaceOf\ LiveAndWorkPersonUnderTwentySixNotAStudent = 250)
加:
aquiredCostsOfIncomeInSamePlaceOf+ LiveAndWorkPersonUnderTwentySixNotAStudent = 250
括号和引号:
('aquiredCostsOfIncomeInSamePlaceOfLive AndWorkPersonUnderTwentySixNotAStudent') = 250
括号和更多引号:
('aquiredCostsOfIncomeInSamePlaceOf' 'LiveAndWorkPersonUnderTwentySixNotAStudent') = 250
我发现唯一有效的是:
aquiredCostsOfIncomeInSamePlaceOfLiveAndWorkPersonUnderTwentySixNotAStudent\
= 250
但我总是可以在“=”括号之后剪切。
你知道有什么解决办法吗?
解决方案
有一种方法可以做到这一点,但不是传统方式:使用字典。
my_vars = {
'aquiredCostsOfIncome' \
'InSamePlaceOfLiveAnd'\
'WorkPersonUnderTwentySix'\
'NotAStudent': 250
}
print(my_vars['aquiredCostsOfIncomeInSamePlaceOfLiveAndWorkPersonUnderTwentySixNotAStudent'])
(注意:不要这样做。只是取一个较短的名字)
推荐阅读
- openflow - Openflow 1.5 与 Openflow 1.4 的改进
- bash - Linux Bash 按唯一列计数和汇总
- python - 如何在 django 中上传到 s3 之前压缩图像?
- mysql - PhpStorm 数据编辑器控制台窗口中的 MySQL 更改分隔符
- firebase - Flutter 多个 Firestore 查询
- c# - 在有限转弯的情况下实现基于网格的寻路问题
- log4net - 当我停止站点时,询问 log4net 只是写到 appender
- php - 带加号按钮的动态选择
- excel - 删除重复数据
- c++ - Qt GUI:groupBox中水平布局的东西错位