DICTIONARY KEYERROR :how to use backslash as a key in python dictionary
DICTIONARY KEYERROR :how to use backslash as a key in python dictionary
syntaxes={
'>':"greater than",
"<": "less than",
"*": "multiplication",
"+": "addition",
'/': "forward slash"
'\': "back slash" # String literal is unterminatedPylance
}
input='>'
print(syntaxes[input])
我试图在 python 中使用反斜杠作为键 "",但它不允许我抛出错误
You need to use "\" double backslash everywhere where ever you need only a single backslash.
In dictionary key as well as while providing input.
syntaxes={
'>':"greater than",
"<": "less than",
"*": "multiplication",
"+": "addition",
'/': "forward slash",
'\': "back slash" # String literal is unterminatedPylance
}
input='\'
print(syntaxes[input])
syntaxes={
'>':"greater than",
"<": "less than",
"*": "multiplication",
"+": "addition",
'/': "forward slash"
'\': "back slash" # String literal is unterminatedPylance
}
input='>'
print(syntaxes[input])
我试图在 python 中使用反斜杠作为键 "",但它不允许我抛出错误
You need to use "\" double backslash everywhere where ever you need only a single backslash.
In dictionary key as well as while providing input.
syntaxes={
'>':"greater than",
"<": "less than",
"*": "multiplication",
"+": "addition",
'/': "forward slash",
'\': "back slash" # String literal is unterminatedPylance
}
input='\'
print(syntaxes[input])