[Tutor] python: how do I create a list of definitions?
rabidpoobear at gmail.com
Fri Jul 20 04:04:42 CEST 2007
elis aeris wrote:
> like, I am doing string substitution:
> if x = 2243:
this will always evaluate to true.
x is being assigned the value of 2243. 2243 is being returned by the
You can observe this in the following situation:
>>> y = x = 2243
As you can see, (x = 2243) assigns the variable name to the integer
2243, then assigns y to this integer object as well.
so in essence you're saying
which is the same as saying 'if ' and anything nonzero, which is True.
so basically the following line
> string = string + "e"
is always being executed.
> if x = 2234:
> string = string + "p"
same with this one.
> how do I create this:
> list = [
> and so forth,
> so I can use it like this:
> for a in range(10):
> If x = list[a]:
If is invalid. Python is case sensitive. 'if' and 'If' are not the same.
Also, you're using an assignment instead of a comparison again.
> string = string + list[a]
You could probably solve this easily with a dictionary.
More information about the Tutor