Latest web development tutorials

Python 練習實例96

Python 100例 Python 100例

題目:計算字符串中子串出現的次數。

程序分析:無。

程序源代碼:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    str1 = raw_input('input a string:\n')
    str2 = raw_input('input a sub string:\n')
    ncount = str1.count(str2)
    print ncount

以上實例輸出結果為:

input a string:
www.w3big.com
input a sub string:
w3big
1

Python 100例 Python 100例