最stroke count
最stroke count意思是輸入一個字元串,統計其中單詞的個數。
在Python中,可以使用split()
方法來分割字元串,並使用len()
函式來統計單詞個數。以下是一個簡單的Python代碼示例:
string = "This is a sample string"
word_count = len(string.split())
print(word_count)
這段代碼將輸出字元串中的單詞數。注意,split()
方法使用空格作為分隔設定,因此它會將連續的空格視為一個分隔設定。如果你想使用其他分隔設定,可以在split()
方法中指定它。