Python (ii)

Source: Internet
Author: User

file Processing

1. File processing mode

R: Open file in read-only mode

W: Open file in write-only mode: If the file exists or has content, it will be the original content, does not exist to create

A: Open file in Append mode

R+b: Open file in read-write mode

W+b: Open file in read-write mode

A+b: Open file in Append and read mode

2. Test:

      Read Only:  f = file (' Aaa.txt ', ' R ')      #只读模式打开              f.readline ()                      #查看文件内容              f.close ()                         #结束        Write only:   f = file (' Aaa.txt ', ' W ')      #只写模式打开              f.write (' New-line ')             #写入内容, will cover              f.clone ()       Append:   f = file (' aaa.txt ', ' a ' \ n)   # Append mode open, add line break    &nbsP;        f.write (' www ')                  #写入内容              f.close ()

---------------------------------------------------------------------

string Processing

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/77/48/wKioL1ZmejSSmV54AAGtPIJr7QQ246.png "title=" 222. PNG "alt=" Wkiol1zmejssmv54aagtpijr7qq246.png "/>------------------------------------------------------------- --

List

1. Concept: Store a set of data equal to an array in another language

2. Example:

    (1) List >>> name_list = [' Zhao ', ' Qian ', ' Sun ']>>> name_ list [' Zhao ',  ' qian ',  ' Sun ']>>> name_list[0] zhao       (2) Additional                >> > name_list.append (' li ')     #append是追加的意思 >>> name_list [' Zhao ',  ' Qian ',  ' Sun ',  ' Li ']    (3) appended to the specified line after >>> name_list.insert (2, ' ' ")      #追加到第二行的后面 >>> name_list[' Zhao ',  ' Qian ',  ' to ',  ' Sun ',  ' li '     (4) Remove  >>>name_list.remove (' Zhao ') >>> name_list[  ' Qian ',   ',  ' Sun ',  ' li ']    (5) statistics show how many times >>> name_list.append (' Zhao ') > >> name_list [' Zhao ',  ' qian ',  ' Sun ',  ' li ', ' Zhao '] >>>name_ List.count (' Zhao ')       #出现了两次2     (6) View location >>> name_list [' Zhao ',  ' qian ',  ' sun ',  ' li ', ' Zhao '] >>> name_list.index (' Qian ') 1       (7) In case of knowing the string position, intercept >>> name_list[' Zhao ',  ' Qian ', ' Sun ',  ' li ', ' Zhou ', ' Wu ', ' Zheng ', ' Wang ' >>>name_list [0:5][' Zhao ',  ' Qian ', ' Sun ',  ' li ', ' Zhou ', ' Wu ']    (8) Intercept >>> name_list[' Zhao ',  ' Qian ', ' Sun ',  ' li ', ' Zhou ', ' Wu ', ' Zheng ', ' Wang ', without knowing the string position >>>name_list[name_list.index (Zhao): Name_list.index (Zhao) +4] #从zhao开始截取四个包括zhao [' Zhao ',  ' Qian ',   ' Sun ',  ' li '

----------------------------------------------------------------------

Meta-group

1. Concept: Non-modifiable, other similar to the list









This article is from the "Ming python" blog, so be sure to keep this source http://pythonzhai.blog.51cto.com/10391994/1720729

Python (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.