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例

0 个评论

要回复文章请先登录注册