>>> str(42)
'42'
>>> int('42')
42
Links to the documentation:
int()str()
str(x) converts any object x to a string by calling x.__str__(), or repr(x) if x doesn't have a __str__() method.
Convert integer to string in Python - Stack Overflow
i am a beginner at python and im trying to convert string to int but it doesn't work
Quick question: Is there a way to get the first three digits of a int without converting it to a string or list?
You probably shouldn't be keeping phone numbers as ints, because they don't behave like ints. You'll never add, subtract, multiply, or divide phone numbers. You will, however, access individual digits of them, so an array is a much more appropriate type. If you absolutely must store them as ints for efficiency reasons (unlikely), then at point of use you should probably just convert them, unless that is too expensive (even more unlikely).
Remember readability is generally more important than minor performance gains, so digits(num)[:3] is much easier to understand than (num-num%le6)/le6 as skier_scott suggests doing.
More on reddit.com