Python input. I have a question

Asked 2 years ago, Updated 2 years ago, 13 views

a = input ("Enter an integer: ")

b = 1

print(int(a) + b)

In this code, if you use an int type in parentheses, it is printed as an int type only in parentheses If it comes out again, it says it has a string value, so I'm asking why. I'm a beginner at coding for the first time, so please explain it easily..

python

2022-09-21 21:49

2 Answers

In a print statement, no matter what you do to a variable, the value in the variable does not change.

Print statements are literally printing, not for storing separately.


2022-09-21 21:49

Int(a) in the print function does not change the actual variable value.

It is just returning by changing the value of a to integer in the int()

a = int (input('integer input:')

If you do this, a will be assigned a value that changed the type to integer.

b = 1
print(b+1) # 2
print(b) # 1

b = b+1
print(b) # 2

It's the same logic as the code above.


2022-09-21 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.