【InternLM】入门岛:Python 基础知识

任务一:使用Python实现简易WordCount函数

在这里插入图片描述
先把标点符号替换为空,把所有字母变成小写
然后遍历所有单词,如果出现过就次数+1,没出现过,就设定次数为1

def wordcount(text):
    cleaned_text = text.replace(",","").replace(".","").replace("?","").replace("!","").replace("\n","").lower()
    words = cleaned_text.split(' ')
    word_count = {}
    for word in words:
        if word in word_count:
            word_count[word] += 1
        else:
            word_count[word] = 1
    return word_count

text = """Hello world!  
This is an example.  
Word count is fun.  
Is it fun to count words?  
Yes, it is fun!"""
print(wordcount(text))

任务二:Vscode远程连接开发机进行python debug

debug单个python文件

在这里插入图片描述
eg: 第一个词,hello,因为没有出现过,所以记一个次数
在这里插入图片描述

使用命令行debug

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置文件生成
在这里插入图片描述
在这里插入图片描述

课程任务跟练

debug单个python文件

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

使用命令行发起python debug

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置文件生成
在这里插入图片描述
在这里插入图片描述
发起debug server的命令
python -m debugpy --listen 5678 --wait-for-client ./myscript.py
用到第三方包debugpy,listen是监听端口,wait-for-client等待连接上才发起debug流程,./myscript.py是debug文件
安装debugpy包
在这里插入图片描述
成功开启debug
在这里插入图片描述
这种方式的好处是可以直接在命令行添加参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值