Python编程:怎么使用Counter对象keys()方法

2024-11-22 04:26:34

1、首先在PyCharm软件中,打开一个Python项目。

Python编程:怎么使用Counter对象keys()方法

2、在Python项目中,新建并打开一个空白的python文件(比如:test.py)。

Python编程:怎么使用Counter对象keys()方法

3、在python文件编辑区中,输入:“from collections import Counter”,导入 collections 模块中的 Counter 类。

Python编程:怎么使用Counter对象keys()方法

4、输入:“cVal = Counter('hello world')”,点击Enter键。

Python编程:怎么使用Counter对象keys()方法

5、接着输入:“x = cVal.keys()”,点击Enter键。

Python编程:怎么使用Counter对象keys()方法

6、然后输入:“print(x)”,打印出相关数据结果。

Python编程:怎么使用Counter对象keys()方法

7、在编辑区域点击鼠标右键,在弹出菜单中选择“运行”选项。

Python编程:怎么使用Counter对象keys()方法

8、在运行结果窗口中查看运行结果,可以看到已经成功地使用Counter对象keys()方法。

Python编程:怎么使用Counter对象keys()方法
猜你喜欢