鱼C论坛

 找回密码
 立即注册
查看: 2265|回复: 2

mask内置变量的魔法方法

[复制链接]
发表于 2017-3-14 20:56:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
In interactive mode, the last printed expression is assigned to the variable _. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example:

>>>
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06
This variable should be treated as read-only by the user. Don’t explicitly assign a value to it — you would create an independent local variable with the same name masking the built-in variable with its magic behavior.

请问怎么创建一个同名的独立本地变量来mask掉内置变量的魔法行为???不懂。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-3-14 21:01:17 | 显示全部楼层
您好!我认为理论上来说,同一个名字的变量只能存在一个,你想要不mask掉那就换一个名字,想要mask掉就用内置变量的名字。名字千千万,施主何必执着~

希望我的回答能对你有帮助,谢谢!祝你在学习的道路上越走越远!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-3-14 21:13:16 | 显示全部楼层
雪山凌狐 发表于 2017-3-14 21:01
您好!我认为理论上来说,同一个名字的变量只能存在一个,你想要不mask掉那就换一个名字,想要mask掉就用内 ...

谢谢你的回答。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2023-9-30 12:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表