0

Why

print(2+3) print(int("2") + int("3")) They both produce same results. Why code long when you can get same output?

2nd Apr 2020, 10:38 AM
Rashid Sultan
Rashid Sultan - avatar
7 ответов
+ 1
Int and str are functions which convert characters into strings into non strings and vice versa. Sometimes when coding you need to use same data types in the same the program but with different (like the data type x=1. When you want to use it as string you write str(x) but when you want this data type to do calculation you use int(x) and so on.
2nd Apr 2020, 10:50 AM
Tricker
+ 2
This code above is for demo and learning. Generally one often has to deal with textlike numbers. Knowledge about converting is necessary.
2nd Apr 2020, 10:44 AM
Oma Falk
Oma Falk - avatar
+ 1
"122"
2nd Apr 2020, 10:45 AM
Oma Falk
Oma Falk - avatar
0
yes. Whats the advantage of coding longer when coding bring same result?
2nd Apr 2020, 10:41 AM
Rashid Sultan
Rashid Sultan - avatar
0
Can you give example of textlike numbers please?
2nd Apr 2020, 10:45 AM
Rashid Sultan
Rashid Sultan - avatar
0
Thanks
2nd Apr 2020, 10:47 AM
Rashid Sultan
Rashid Sultan - avatar
0
Okay. Thanks for explaining
2nd Apr 2020, 10:51 AM
Rashid Sultan
Rashid Sultan - avatar