0

Type conversion

sorry guys but I can't wrap my head around this one! can't someone give me an example for its positive uses?

31st Jul 2016, 12:18 PM
McKinley Kay
2 Answers
0
for example: Users input always returns a string. imagine you'r making a calculator, you need numbers for that so you need to make the strings, numbers. hope it helps
1st Aug 2016, 10:01 AM
Tom Post
Tom Post - avatar
0
Hey. In Python you don't need to explicitly declare your variable, just assign some information to that variable name and Python understands the type. For example, a = "blabla". Python understands variable a have a string data. If b = "7" so it's also a string just like "blabla". You can't do any math with strings (don't consider concatenation or copying as math operations). If you want to add variable b to the integer 8, you can't. They're two different types. It's the same thing you're trying to add "blabla" to 8 or one orange to one hammer. So if you can, you convert variable b to integer and now you can add to 8. Python always expects from input function a string, so if you wanna do some math with value, convert it float or integer. Hope it helps.
3rd Aug 2016, 2:21 AM
Henrique Santana
Henrique Santana - avatar