简体   繁体   English

你可以在 Python 中的字典中使用“\”吗?

[英]Can you use "\" in a dictionary inside Python?

I'm creating a variation of the vigenere cipher using all the ASCII characters using a dictionary.我正在使用字典创建使用所有 ASCII 字符的 vigenere 密码的变体。 The first few lines are okay, but then I get an error for the value 3. vigenereDictionary = { "@": "0", "%": "1", "+": "2", "\": "3", "/": "4", ... I want to have it so that when a user types \ it will output/take the value 3, however, I understand backslash is a special character, is there any way to implement this.前几行没问题,但是值 3 出现错误。 vigenereDictionary = { "@": "0", "%": "1", "+": "2", "\": "3", "/": "4", ...我想拥有它,这样当用户键入 \ 时,它将输出/取值 3,但是,我知道反斜杠是一个特殊字符,有什么办法可以实现这一点。

" 它是字符串的转义字符,请尝试使用 "\",它会转义反斜杠本身。 – ChrisOram "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM