Friday 15 February 2013

python - Counting from 1 to infinity without assignment -



python - Counting from 1 to infinity without assignment -

is possible create python count 1 infinity without using assignment operator of kind (=,=+, etc)? of can't import or phone call code contains assignment operator.

i managed find solution works on idle because uses _:

if 1: 1 while 1: x in range(_+1, _*3): x

can think of solution work? (it without using _)

here 1 possible solution:

for x in [0]: while 1: x in [x+1]: print x

it works because:

for var in [value]: pass

is same as

var = val

therefore can write want without using = operator! remember python performing assignment behind scenes.

name = raw_input('whats name?') #with = operator name in [raw_input('whats name?')]: pass #without = operator

you can utilize function well:

def assign(lval, val): globals().update({lval:val})

python python-2.7 python-3.x

No comments:

Post a Comment