Avatar ·

How to split an integer into individual digits and output them separated by commas?

📁 List, string, Advanced Python Topics, example

for example there is a variable a = 987

how to output in this format:

9,8,7

maybe somehow through a for() loop and then write it to a list and output it using split with a comma, but that would be a lot of code, how can it be implemented more concisely?

Avatar ·

If the essence of the question is comparing values and types, you can do it like this:

def strict_eq(obj1, obj2):    if type(obj1) != type(obj2):        retu False    retu obj1 == obj2

In [4]: strict_eq(0, False)Out[4]: False

PS you can go even further and for numeric types compare numbers up to a certain precision to avoid known floating-point issues:

Log in to leave an answer

Blogs