Python Exercise Example 98

Python 100例Python 100 Examples

Question:Input a string from the keyboard, convert all lowercase letters to uppercase letters, then output it to a disk file "test" for storage.

Program analysis:None.

Program source code:

Example

#!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': fp = open('test.txt','w') string = raw_input('please input a string:\n') string = string.upper() fp.write(string) fp = open('test.txt','r') print fp.read() fp.close()

The output result of the above example is:

please input a string:
example.com
example.com

Python 100例Python 100 Examples

Other extensions