社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

在文本文件Python中搜索大写单词的数量

Fulltimehustle • 5 年前 • 1515 次点击  

我需要帮助整理文本文件

我试过多种不同的for循环。我还试着去掉所有空格,并在文件中逐个计算字母数。我还尝试了strip函数的多种变体和不同的if语句

for character in file:
    if character.isupper():
        capital += 1
        file.readline().rstrip()
        break

print(capital)

我希望程序读取文档中的每个单词或字母,并返回其中包含的大写单词总数。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54929
 
1515 次点击  
文章 [ 3 ]  |  最新文章 5 年前