Latest web development tutorials

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:
w3big.com
w3big.com

Python 100例 Python 100例