![]() |
VOOZH | about |
With the help of sympy.digits() method, we can find the digits of a given integer in any given base in SymPy.
Syntax: digits(n, t=10) Parameter: n - It denotes an integer. b - It denotes an base integer(optional). Default for b is 10. Returns: Returns a list of the digits of n in base b. The first element in the list is b (or -b if n is negative).
Example #1:
Output:
Digits of 7524 in base 10 = [10, 7, 5, 2, 4]
Example #2:
Output:
Digits of 33 in base 2 = [2, 1, 0, 0, 0, 0, 1]
Example #3:
If the number is negative, the negative sign will be placed on the base (which is the first element in the returned list)
Output:
[-10, 3, 5]