a=input() print(a['birth'])
In input brackets, {'birth' : '1234', 'name' : 'abc'} are all yours, is there any way to get an error? Please tell me why there is an error ㅠ<
python dictionary
First, input()
treats everything you enter as a string. Because the {'birth':'1900', 'name':'frank'}
that you enter will be a string, you must replace it with a dictionary data type. You can then do the ast module , which changes the string to a dictionary data type.
import ast
a = "{'birth':'1900', 'name':'frank'}"
a_dic = ast.literal_eval(a)
print(a_dic['birth'])
© 2024 OneMinuteCode. All rights reserved.