Alex Rivera | Logout

Are there any declaration keywords in Python?

Asked 2009-02-20T22:34:34.903
11

Are there any declaration keywords in Python, like local, global, private, public etc.? I know that variable types are not specified in Python; but how do you know if the code x = 5 creates a new variable, or sets an existing one?

Edit
Report

1 Answer

8

It doesn't look like the asker is trying to assign a type, just to specify that this a declaration, not an assignment.

Looks like you are looking for something like javascript has:

var x = 5;

The concept of the declaration keyword in javascript is to ensure that you are making a new object in the current scope and are not simply changing some other variable of the same name.

Python does not have this feature. The programmer has to make sure that he or she is not reassigning preexisting names.

answered 2009-02-20T22:53:07.447

Your Answer