1 | initial version |
If you're planning on running the function from say the notebook or and interactive prompt, you can do something like the following technique:
def f(n):
for i, value in enumerate(n.digits(2)):
globals()['x%s'%i] = value
Then, you can do something like:
sage: f(8)
sage: x0
0
sage: x3
1
A more Pythonic way to do things (without messing with the global namespace) would be something like:
def f(n):
return n.digits(2)
and then:
sage: x = f(n)
sage: x[0]
0
sage: x[3]
1
2 | Fix a typo. |
If you're planning on running the function from say the notebook or and interactive prompt, you can do something like the following technique:
def f(n):
for i, value in enumerate(n.digits(2)):
enumerate(Integer(n).digits(2)):
globals()['x%s'%i] = value
Then, you can do something like:
sage: f(8)
sage: x0
0
sage: x3
1
A more Pythonic way to do things (without messing with the global namespace) would be something like:
def f(n):
return n.digits(2)
Integer(n).digits(2)
and then:
sage: x = f(n)
f(8)
sage: x[0]
0
sage: x[3]
1