Python Exercise Example 70
**Problem:** Write a function to find the length of a string; input the string in the main function and output its length.
**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 Examples