判断以下字符串中单字符是否出现2次 "Sjbsnt7BaFdW4u2hZRmpIExVPeNDfo9yiJH8Gq3v=gQkTz/MYXLlc1OCKw+6Ar50U"
时间: 2024-03-20 17:41:56 浏览: 54
以下是判断单字符是否出现2次的 Python 代码:
```python
s = "Sjbsnt7BaFdW4u2hZRmpIExVPeNDfo9yiJH8Gq3v=gQkTz/MYXLlc1OCKw+6Ar50U"
for c in s:
if s.count(c) == 1:
print(c, "appears once.")
elif s.count(c) == 2:
print(c, "appears twice.")
else:
print(c, "appears more than twice.")
```
输出结果为:
```
S appears once.
j appears once.
b appears once.
s appears once.
n appears once.
t appears once.
7 appears once.
B appears once.
a appears once.
F appears once.
d appears once.
W appears once.
4 appears once.
u appears once.
2 appears once.
h appears once.
Z appears once.
R appears once.
m appears once.
p appears once.
I appears once.
E appears once.
x appears once.
V appears once.
P appears once.
e appears once.
N appears once.
D appears once.
f appears once.
o appears once.
9 appears once.
y appears once.
i appears once.
J appears once.
H appears once.
8 appears once.
G appears once.
q appears once.
3 appears once.
v appears once.
= appears once.
g appears once.
Q appears once.
k appears once.
T appears once.
z appears once.
/ appears once.
M appears once.
Y appears once.
X appears once.
L appears once.
l appears once.
c appears once.
1 appears once.
O appears once.
C appears once.
K appears once.
w appears once.
+ appears once.
6 appears once.
A appears once.
r appears once.
5 appears once.
0 appears once.
U appears once.
```
可以看到,所有单字符都只出现了一次,没有出现两次,因此答案是:没有单字符出现两次。
阅读全文