如何教Python“变量” [英] How to Teach Python "Variables"

查看:52
本文介绍了如何教Python“变量”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


IIRC,我曾经看过Python没有变量的解释。在

感觉,比方说,C,而且从名称绑定到

对象。有没有人有链接?


谢谢,

Ami

Hello,

IIRC, I once saw an explanation how Python doesn''t have "variables" in
the sense that, say, C does, and instead has bindings from names to
objects. Does anyone have a link?

Thanks,

Ami

推荐答案

noneaécrit:
none a écrit :

你好,


IIRC,我曾经看过Python如何解释''在某些意义上,C表示变量

,而是将名称绑定到

对象。有没有人有链接?


谢谢,


Ami
Hello,

IIRC, I once saw an explanation how Python doesn''t have "variables"
in the sense that, say, C does, and instead has bindings from names to
objects. Does anyone have a link?

Thanks,

Ami



那个这是我经常听到的东西,我不知道。不知怎的,我不知道
了解C变量是如何不像python绑定的(差异是因为C变量是静态类型的并且完全消失在

运行时间;这些差异是否足够重要以保证这样的转移

术语?(是的还有一些其他的差异,但是然后问了

的问题在教育学的背景下,观众被引入基础知识。)


我的意思是:不是C变量也从名称绑定到对象?或者什么?

That''s something I''ve often heard and I don''t get it. Somehow I don''t
understand how C variables are not like python bindings (the differences
being that C variables are statically typed and completely disappear at
run-time; are these differences important enough to warrant such a shift
in terminology ? (yes there are some other differences, but then the
question is asked in a context of pedagogy, where the audience is
introduced to the basics))

I mean : aren''t C variables also bindings from names to objects ? Or what ?


AurélienCampéasschrieb:
Aurélien Campéas schrieb:

noneaécrit:
none a écrit :

>您好,

IIRC,我曾经看过Python没有变量的解释。在某种意义上说,比方说,C确实存在,而是从名称到对象具有绑定。有没有人有链接?

谢谢,

Ami
> Hello,

IIRC, I once saw an explanation how Python doesn''t have
"variables" in the sense that, say, C does, and instead has bindings
from names to objects. Does anyone have a link?

Thanks,

Ami



那是我的东西经常听到,我不明白。不知怎的,我不知道
了解C变量是如何不像python绑定的(差异是因为C变量是静态类型的并且完全消失在

运行时间;这些差异是否足够重要以保证这样的转移

术语?(是的还有一些其他的差异,但是然后问了

的问题在教育学的背景下,观众被引入基础知识。)


我的意思是:不是C变量也从名称绑定到对象?或者是什么 ?


That''s something I''ve often heard and I don''t get it. Somehow I don''t
understand how C variables are not like python bindings (the differences
being that C variables are statically typed and completely disappear at
run-time; are these differences important enough to warrant such a shift
in terminology ? (yes there are some other differences, but then the
question is asked in a context of pedagogy, where the audience is
introduced to the basics))

I mean : aren''t C variables also bindings from names to objects ? Or what ?



存在重大差异。在C中,你的名字指向

物理内存位置 - 固定位置,即。

因此你可以做到例如

some_struct a,b;


a = b = some_struct_value;


a.bar = 10;

b.bar = 20;


现在a.bar与b.bar不同


这与python完全不同语义,其中

a = b = some_object


a.bar = 10

b.bar = 20


将导致两次操作相同的对象。

所以python变量更像是C中的指针。


Diez

There are cruicial differences. In C, you have names pointing to
physical memory locations - fixed locations, that is.

Thus you can do e.g.

some_struct a, b;

a = b = some_struct_value;

a.bar = 10;
b.bar = 20;

Now a.bar will be different from b.bar

This is totally different from python semantics, where
a = b = some_object

a.bar = 10
b.bar = 20

will result in both times the same object being manipulated.

So python variables are more equivalent to pointers in C.

Diez


AurélienCampéas写道:
Aurélien Campéas wrote:

noneaécrit:
none a écrit :

>您好,

IIRC,我曾经看过Python没有变量的解释。在某种意义上说,比方说,C确实存在,而是从名称到对象具有绑定。有没有人有链接?

谢谢,

Ami
> Hello,

IIRC, I once saw an explanation how Python doesn''t have
"variables" in the sense that, say, C does, and instead has bindings
from names to objects. Does anyone have a link?

Thanks,

Ami



那是我的东西经常听到,我不明白。不知怎的,我不知道
了解C变量是如何不像python绑定的(差异是因为C变量是静态类型的并且完全消失在

运行时间;这些差异是否足够重要以保证这样的转移

术语?(是的还有一些其他的差异,但是然后问了

的问题在教育学的背景下,观众被引入基础知识。)


我的意思是:不是C变量也从名称绑定到对象?或者是什么 ?


That''s something I''ve often heard and I don''t get it. Somehow I don''t
understand how C variables are not like python bindings (the differences
being that C variables are statically typed and completely disappear at
run-time; are these differences important enough to warrant such a shift
in terminology ? (yes there are some other differences, but then the
question is asked in a context of pedagogy, where the audience is
introduced to the basics))

I mean : aren''t C variables also bindings from names to objects ? Or what ?



谢谢。


很可能你是对的 - 我不知道。然而,似乎有一些

的差异。举几个例子:

1.无论你是否在

中存储东西,都存在一个C变量。对于python变量而言,情况并非如此。 - 所以对于独立存在的东西来说,它更像是一个

名称。

2.当超出范围时,C变量(或C ++对象)完全消失,

但是对于Python对象来说并不一定如此。

3. C ++引用的语义如果a = b,你写的是ac =

3,然后是bc == 3.在Python中也是如此。但是如果a = b,并且

然后你写b = 5,那么a仍然绑定到b的原始值,

所以它不完全是喜欢参考。

4.等等


一方面,你显然是对的,也许没有空间

用于范式转换。 OTOH,如果最简单的解释是它就像一个

C / C ++变量/引用/指针除了1,2,3,4 ......,那么可能

它是不同的。我只是不知道,因此我的问题。

Thanks.

It''s very possible you''re right - I don''t know. There seem to be some
differences however. To name a few:
1. A C variable exists regardless of whether you''re storing something in
it. Not so for a python "variable" - so it''s a bit really more like a
name for something that exists independently.
2. C variables (or C++ objects) completely disappear when out of scope,
but that''s not necessarily true of Python objects.
3. C++ references have the semantics that if a = b, and you write a.c =
3, then b.c == 3. This is also true in Python. But then if a = b, and
then you write b = 5, then a is still bound to the original value of b,
so it''s not exactly like a reference.
4. Etc.

So on the one hand, you''re obviously right, and maybe there''s no room
for a paradigm shift. OTOH, if the simplest explanation is "it''s like a
C/C++ variable/reference/pointer except for 1, 2, 3, 4,...", then maybe
it is different. I just don''t know, hence my question.


这篇关于如何教Python“变量”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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