Python中的文字和变量有什么区别? [英] What is the difference between literal and variables in Python?
本文介绍了Python中的文字和变量有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Python的初学者,但是我在字面量和变量之间感到困惑.
I'm a beginner user for Python, but I get confused between literal and variables.
这是我对文字的了解:"a"+"b"
This is what I know about a literal: "a"+"b"
和变量:sentence="a"+"b"
推荐答案
文字是表示固定(const
)值的符号.
变量是与符号名称关联的存储位置(如果需要,可以指向).
A literal is notation for representing a fixed (const
) value.
A variable is storage location associated with a symbolic name (pointed to, if you'd like).
最好在使用中进行解释:
It's best explained in use:
foo = bar(42)
^ ^ ^
| | |--- literal, 42 is *literally* 42
| |------- function, also represents "something" in memory
|------------- variable, named "foo", and the content may vary (is variable)
这篇关于Python中的文字和变量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文