0
In what circumstances would I need to turn a integer to a string and vice versa
Just wondering
4 ответов
0
A string is a sequence of characters, an int is a number. They are very different things.
When you take input from the console, for example, you get a string. If you read from a text file, you get a string. If you read from a network resource using a text based protocol, e.g. HTTP, you get a string.
When you need to write to the console, you write a string, when you write to a text file, you write a string. When you write to a network resource using a text based protocol, you write a string.
What happens in between those two lists of examples, that might be calculation with numbers, quantities, currencies, ... So, between getting data, and writing data, you may need to convert from string to int (or float) and back.
+ 1
working with string you need string
working with numbers you need integer
I think it is obvious!
0
To integer: int() --> math operations
To string: str()