Python 练习实例70

约 296 字 更新于 2026-11-18 5iyo.com

Python 练习实例70

题目:写一个函数,求一个字符串的长度,在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.