Python 練習實例98

Python 100例 Python 100例

題目:從鍵盤輸入一個字串,將小寫字母全部轉換成大寫字母,然後輸出到一個磁片檔"test"中保存。

程式分析:無。

程式源代碼:

實例

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

以上實例輸出結果為:

please input a string:
xuhuhu.com
xuhuhu.com

Python 100例 Python 100例