0

In what circumstances would I need to turn a integer to a string and vice versa

Just wondering

24th Jan 2022, 7:28 AM
Raven
Raven - avatar
4 Respuestas
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.
24th Jan 2022, 7:45 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
working with string you need string working with numbers you need integer I think it is obvious!
24th Jan 2022, 7:53 AM
Shadoff
Shadoff - avatar
0
To integer: int() --> math operations To string: str()
24th Jan 2022, 7:29 AM
Lisa
Lisa - avatar