python 怎么判断字符串中的某个字符是不是斜杠✀尀✀

2025-04-07 06:52:55
推荐回答(3个)
回答1:

应该是对的。

def scanSlash():
    s="关"

    for i in range(6):

        if s[i]=='\\':
            print "@",
        else:
            print s[i],
scanSlash()

结果:

回答2:

# 因为 

s = u'关' 
len(s) == 1
# True

# 也就是用 '\\' 与 '关' 比较 肯定是不匹配的
# 去python的doc看了一眼
# http://docs.python.org/2/howto/unicode.html

s2 = repr(s)    # s = u'关' 
'\\' in s2
# True

回答3:

因为\u..表示后面的4为数字是一个unicode字符