• 直播介紹
  • 相關推薦
  • 電子產(chǎn)業(yè)圖譜
申請入駐 產(chǎn)業(yè)圖譜

Python基礎教程之文件操作

2018/05/15
101
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論

課程簡介

打印到屏幕

最簡單的輸出方法使用print語句,你可以給他傳遞零個或多個用逗號隔開的表達式?;蛘呤褂谜嘉环?/p>

讀取鍵盤輸入

Python提供了兩個內(nèi)置函數(shù)從標準輸入讀入一行文本,默認的標準輸入是鍵盤。如下:

raw_input() input()函數(shù)

raw_input函數(shù)

raw_input([prompt])函數(shù)從標準輸入讀取一個行,并返回一個字符串(去掉結(jié)尾的換行符):

str=raw_input(“Enter your input:”);

print“Received input is:”,str

這將提示你輸入任意字符串,然后再屏幕上顯示相同的字符串。

當我輸入“Hello Python!”它的輸入如下:

Enter your input:Hello Python

Received input is:Hello Python

input函數(shù)

input([prompt])函數(shù)和raw_input([prompt])函數(shù)基本可以互換,但input會假設你的輸入是一個有效的Python表達式,并返回運算結(jié)果。

str=input(“Enter your input:”);

print“Received input is:”‘str

這會產(chǎn)生如下的對應著輸入的結(jié)果:

Enter your input:[x*5 x in range(2,10,2)]

Received input is : [10,20,30,40]

打開和關閉文件

File對象的屬性

close()方法

相關推薦

電子產(chǎn)業(yè)圖譜