为什么我切出卡片套装表情符号后字符串不相等?
Python 3.9
cards = ['♥️A','♠️2','♣️3']
ref_list = ['A','2','3']
for a in cards:
print(a[1:])
print(a[1:] in ref_list)
输出是
A
False
️2
False
️3
False
如何修改代码以使其正常工作? (使输出true
?)
Python 3.9
cards = ['♥️A','♠️2','♣️3']
ref_list = ['A','2','3']
for a in cards:
print(a[1:])
print(a[1:] in ref_list)
the output is
A
False
️2
False
️3
False
How should I revise the code to make it work? (Make the output True
?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到 Unicode 的世界!
此字符串中的红心由 黑心套装 和 变体选择器代码点,因此您的完整字符串有 3 个代码点。
考虑不使用字符串连接来表示此数据,并定义一个数据类或至少一个像 <代码>('♥️', 'A') 代替。
Welcome to the world of Unicode!
The red heart in this string is composed of the Black Heart Suit and the Variation Selector code points, so your complete string has 3 code points.
Consider not using string concatenation to represent this data, and define a dataclass or at least a tuple like
('♥️', 'A')
instead.