What is the function of function COUNT() in python
Oct 29, 2020 am 09:30 AMThe function of the function COUNT() in python is to count the number of times a certain character appears in a string. The syntax is [str.count("char", start,end)], where str is the character to be counted. , star is the starting position of the index string, and end is the end position of the index string.
count() function
Description: Count the number of times a certain character appears in a string. You can select the starting and ending positions of the string index.
Syntax: str.count("char", start,end) or str.count("char") -> int Returns an integer
str —— is the character to be counted (can be a single character or multiple characters).
star - is the starting position of the index string, the default parameter is 0.
end - is the end position of the index string. The default parameter is the string length, which is len(str).
Program example:
str = "i love python,i am learning python" print(str.count("i")) #star 和end 为默认参数 print(str.count("i",2)) # star值为2,end值为默认参数 print(str.count("i",2,5)) #star值为2,end值为5 print(str.count("am")) #多字符统计
Program running result:
3 2 0 1
Related free learning recommendations: python video tutorial
The above is the detailed content of What is the function of function COUNT() in python. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
