python - Python:处理大字符串值 - if 语句无法正常工作?
问题描述
我有这个大字符串值,大约 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'%'
我尝试将字节字符串转换为带有“解码”的纯字符串,结果如下:
strPage6=strPage.decode('utf-8')
[...]
330th character is NOT '%'
e
基本上,我希望得到以下结果:
330th character is '%'
%
感谢您的帮助!
解决方案
您是否尝试过 strPage6[330]==b"%"?– 凯尔伍德
等式是否正确
推荐阅读
- javascript - Same content on many different Websites
- objective-c - VLCKit无法在objective-c的可可编程中播放视频?
- mysql - Error in inserting comparison 'last modifed date' record between 2 tables into another table
- c - LuaSockets library will not correctly load
- javascript - Angular 6 Error Handling not showing toasts
- python - Installing RTree and geopandas in windows 10 64 bit OS
- java - 为什么响应字段之一具有“_id”字段的值?
- tableau-api - What is the new extension feature in Tableau about? Can you name a useful example?
- node.js - Node.js clustering is slower than single threaded mode
- java - java-如何在MySQL中获取文件路径并从目录中获取后续文件?