Python Practice Example 70

Python 100例Python 100 Examples

Topic:Write a function to find the length of a string. Input the string in the main function and output its length.

Program analysis:None.

Program source code:

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

The output of the above example is:

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

Python 100例Python 100 Examples

Other extensions