# 9 examples of 'how to split a number in python' in Python

Every line of 'how to split a number in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``28def num_split(s: str) -&gt; Tuple[Union[int, str], ...]:29    """Splits a word into sequences of numbers and non-numbers.3031    Creates a tuple from these where the number are converted into int datatype.32    That way a naturual sort can be implemented.33    """34    parts: List[Union[int, str]] = []35    for part in re.split(r'(\d+)', s):36        try:37            parts.append(int(part))38        except ValueError:39            parts.append(part)4041    return tuple(parts)``
``68def splitnum(self, value):69    for elem in self.cards:70        if elem &gt; value:71            continue7273        out = []74        if value == 0:75            div, mod = 1, 076        else:77            div, mod = divmod(value, elem)7879        if div == 1:80            out.append((self.cards[1], 1))81        else:82            if div == value:  # The system tallies, eg Roman Numerals83                return [(div * self.cards[elem], div*elem)]84            out.append(self.splitnum(div))8586        out.append((self.cards[elem], elem))8788        if mod:89            out.append(self.splitnum(mod))9091        return out``
``156def get_numbers(num):157    card_and_port = str(num)158    card_and_port = re.split('/|-',card_and_port)159    card = card_and_port[0]160    fromPort = card_and_port[1]161    toPort = fromPort if len(card_and_port) &lt;= 2 else card_and_port[2]162    return card, fromPort, toPort``
``143def split_decimal(value):144    import decimal145    decimal.getcontext().prec = 2146    d = decimal.Decimal(value)147    i = int(d)148    return (i, d - i)``
``143def _split_basic(string):144    """145    Split a string into a list of tuples of the form (key, modifier_fn,146    explode) where modifier_fn is a function that applies the appropriate147    modification to the variable.148    """149    tuples = []150    for word in string.split(','):151        # Attempt to split on colon152        parts = word.split(':', 2)153        key, modifier_fn, explode = parts[0], _identity, False154        if len(parts) &gt; 1:155            modifier_fn = functools.partial(156                _truncate, num_chars=int(parts[1]))157        if word[len(word) - 1] == '*':158            key = word[:len(word) - 1]159            explode = True160        tuples.append((key, modifier_fn, explode))161    return tuples``
``83def test_splitNumber(self):84    self.assertEqual(splitNumber("0222112222120000"),[0,2,2,2,1,1,2,2,2,2,1,2,0,0,0,0])``
``59def _split_float_to_numerator_and_denominator(float_data: float) -&gt; tuple:60    assert 1.0 &gt; float_data &gt;= 061    str_float: str = format(decimal.Decimal(str(float_data)), 'f')62    str_decimal: str = str_float[str_float.find('.') + 1:]63    numerator = int(str_decimal)64    denominator = 10 ** len(str_decimal)65    return numerator, denominator``
``12def extractnumbers(s):13    return tuple(map(int,re.findall("(\d+)\.(\d+)\.(\d+)",str(s))[0]))``
``20def ParseNumber(number):21    if number.startswith('0x'):22        return int(number[2:], 16)23    else:24        return int(number)``