I want to see the data type of input, but why does this come out as str?crying

Asked 2 years ago, Updated 2 years ago, 21 views

From Python

a = input()


print(type(a[0]))
print(type(a[1]))
print(type(123))

If you enter 12 like this,

<class 'str'>
<class 'str'>
<class 'int'>

Why does a[0] come out like this and a[1] come out as str when I know it's 1 and 2?

python

2022-09-22 18:48

2 Answers

a = '12'

# On the other hand,

a[0] = '1' #Still string
a[1] = '2' #Still string

1 and '1' are different.


2022-09-22 18:48

In fact, in many cases, reading the Help will solve the problem. Make the reference available immediately.

The input is a built-input is a built-in function.

The built-in function is built-in within python, so it should be described in detail in the help.

https://docs.python.org/ko/3/library/functions.html#input

If there is a prompt factor, write it to the standard output without putting an open letter at the end. The function then reads a line from the input, converts it into a string, and returns it (removes the line break character at the end of the line). Reading the EOF causes an EOFError.


2022-09-22 18:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.