Python 練習(xí)實(shí)例70

Python 100例 Python 100例

題目:寫(xiě)一個(gè)函數(shù),求一個(gè)字符串的長(zhǎng)度,在main函數(shù)中輸入字符串,并輸出其長(zhǎng)度。

程序分析:無(wú)。

程序源代碼:

#!/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)

以上實(shí)例輸出結(jié)果為:

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

Python 100例 Python 100例