繁体   English   中英

Python:处理大字符串值 - 如果语句不能正常工作?

[英]Python: handling a large string value - if statement not working properly?

我有一个很大的字符串值,大约有 500 个字符,称为“strPage6”,我想看看这个字符串的第 n 个位置是否具有带有 if 语句的“%”值,但没有成功。

#see if 330th character has value '%'
if (strPage6[330:331]=="%"):
   print("330th character is '%' ")
   print(strPage6)
else:
   print("330th character is NOT '%' ")
   print(strPage6)

我的终端返回以下值:

330th character is NOT '%'
b'%'

我尝试将字节字符串转换为带有 'decode' 的普通字符串,结果如下:

strPage6=strPage.decode('utf-8')
[...]

330th character is NOT '%'
e

基本上,我希望得到以下结果:

330th character is '%'
%

感谢您的帮助!

你试过 strPage6[330]==b"%" 吗? – 凯尔伍德

方程是否正确

暂无
暂无

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

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