Python编程之求字符串长度

版权声明:此篇博文为博主心血o(╥﹏╥)o,如要转载请注明来源,勿忘心安! https://blog.csdn.net/dyq1995/article/details/89064942

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

please input a string:
abcef
the string has 5 characters.

please input a string:
abchgby
the string has 7 characters.

please input a string:
nhbygtrscv
the string has 10 characters.

猜你喜欢

转载自blog.csdn.net/dyq1995/article/details/89064942