p ython英文字符统计
时间: 2023-07-11 08:40:06 浏览: 131
使用Python语言实现字符的统计.docx
Sure! Here's a Python code to count the number of English characters in a string:
```python
def count_english_characters(string):
count = 0
for char in string:
if char.isalpha() and char.isascii():
count += 1
return count
```
You can call this function with a string as an argument to count the number of English characters in it. For example:
```python
my_string = "Hello, World! 你好,世界!"
english_count = count_english_characters(my_string)
print("Number of English characters:", english_count)
```
This will output:
```
Number of English characters: 13
```
阅读全文