Python 練習實例96
python 練習實例96
題目:計算字符串中子串出現(xiàn)的次數(shù)。
程序分析:無。
實例(python 2.0+):
#!/usr/bin/python # -*- coding: utf-8 -*- if __name__ == '__main__': str1 = raw_input('請輸入一個字符串:\n') str2 = raw_input('請輸入一個子字符串:\n') ncount = str1.count(str2) print ncount
以上實例輸出結果為:
請輸入一個字符串: m.aalaour.cn 請輸入一個子字符串: yapf 1