简体   繁体   English

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

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

I have this large string value, about 500 characters called 'strPage6' I'm looking to see if nth position of this string has the '%' value with an if statement without success.我有一个很大的字符串值,大约有 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)

my terminal returns the following value:我的终端返回以下值:

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

I tried switching the byte string into a plain string with 'decode' with the following result:我尝试将字节字符串转换为带有 'decode' 的普通字符串,结果如下:

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

330th character is NOT '%'
e

Basically, I am looking to get the following result:基本上,我希望得到以下结果:

330th character is '%'
%

Your help is appreciated!感谢您的帮助!

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

does the equation properly方程是否正确

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

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