Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 70

Python Exercise Example 70

Python 100 Examples Python 100 Examples

**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 Python 100 Examples