Python编程之求字符串长度

匿名 (未验证) 提交于 2019-12-02 22:11:45

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

文章来源: https://blog.csdn.net/dyq1995/article/details/89064942
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!