Latest web development tutorials

Python 練習實例70

Python 100例 Python 100例

題目:寫一個函數,求一個字符串的長度,在main函數中輸入字符串,並輸出其長度。

程序分析:無。

程序源代碼:

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

if __name__ == '__main__':
    s = raw_input('please input a string:\n')
    print 'the string has %d characters.' % len(s)

以上實例輸出結果為:

please input a string:
abc
the string has 3 characters.

Python 100例 Python 100例