程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Introduction to python, can you talk about the basic rules of Python file operation

編輯:Python

ditto But not enough words I hope you can say python Basic rules for file operation Don't be particularly detailed
I learned before c++ Feeling c++ The difficulty of file operation is OK I do not know! python What about?
Basic is OK




Take the answer :

The most basic is reading and writing ,c++ Same thing in China , Yes c++ Basic words ,python It's a little bit easier
Reading documents

f = open("1.txt","r") #open Is a built-in function , There are two parameters 1. file name ( With suffix ) 2. Pattern Such as r yes read Pattern , Read mode f.read(5) # Express reading 5 Characters f.close # Close file , and c++ equally 

Writing documents

f = open("1.txt","r") #open Is a built-in function , There are two parameters 1. file name ( With suffix ) 2. Pattern Such as w yes write Pattern , Write mode f.write("hello") # Express the hello write file f.close # Close file , and c++ equally 

This is the most basic
Others you can search It's all pretty simple
If it helps, please adopt it !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved