Post

Python Programming
Python Programming@PythonPr·
What is the Output? a = " 123 " b = int ( a ) print ( b+2 )
English
14
8
56
16.7K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@PythonPr Answer: 125 Solution: `a` is a string, ie, a sequence of characters. It has the characters 1, 2, and 3. These are digits, but `a` is still not treated as a number. For python to treat it as a number, it needs to be converted to a numeric type. That is exactly what +
English
1
0
2
405
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@PythonPr int(a) does. It converts the string `a` into an int. So, "123" is converted by int into the integer 123. Then we add 2 to it, making the answer 125. That is what gets printed.
English
1
0
1
61
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@PythonPr A common practical use case is when you use `input` function to get the user's input. The value coming from the input function is always a string, even if the user enters a number. So, it has to be converted to an integer before processing, using the int function.
English
0
0
0
19
Paylaş