python newbie

tasjaevan at gmail.com tasjaevan at gmail.com
Fri Nov 2 17:50:27 CET 2007


On Nov 2, 3:35 pm, Jim Hendricks <j... at bizcomputinginc.com> wrote:
>
> This sounds like an issue of terminology.  I understand that I don't
> declare variables like I would in C or Java, but that they are
> implicitly declared via the first assignment.  And the define objects
> and bind a name to them makes no sense to me.  I can only assume that if
> I say: my_file = open( ... the "techy" explaination is that the open
> function defines a file object and binds the name my_file to it.  To me,
> it's easier to say that the open function creates a file object and
> assigns a reference to the my_file variable.  If my_file does not exist,
> it is created, if my_file does exist, prior to the assignment, the type
> of my_file is checked to ensure type safety.
>

Objects have types, names (what you're calling variables) don't.

  my_file = open ...

binds the name 'my_file' to a file object. A subsequent

  my_file = 7

will bind the name 'my_file' to an int object. No type-checking
involved (but neither is there any loss of type safety).


James





More information about the Python-list mailing list