Python Route 2

Source: Internet
Author: User

Day3

1. Collection

1.1 Generation,

Adding a set operation to a list by collection

1.2 episodes are also disordered.

Relationship Testing

1.3 Intersection

Collection. Intersection (collection) or Operators &

1.4 and set

Collection. Union (Collection) or operator |

1.5 difference Set

Collection. Difference (collection) or operator-

Meaning in the first set, but not in the second set

1.6 Judging subcollections and parent sets

Collection. Issubset (collection)

Collection. Issuperset (collection)

1.7 Reverse Difference Set

Collection. Symmatric_difference (collection), which takes out the elements that are not in each of the two sets. Or operator ^

1.8 Intersection is empty

Collection. Isdisjoint (collection), if two sets do not intersect, it is true

2, the operation of the collection, additions and deletions to check

2.1 Add

Collection. Add (), adding a single

collection. Update ([]), adding multiple items

2.2 Delete

Collection. Remove () or collection. Discard

2.3 Deciding whether to belong to a collection

Element in collection

The syntax is the same as the dictionary, and the syntax of the list is the same

3. File operation

3.1 File handle is the file memory object

Open (filename, encoding= "Utf-8")

3.2 Read

File handle. Read ()

3.3 Open

Read-Only open ("Name", ' R ', encoding= "Utf-8")

Write only open ("Name", ' W ', encoding= "Utf-8")

Add mode open ("Name", ' a ', encoding= "Utf-8")

3.4 Print the first 5 lines of a file

Using Loop print (File.read ())

Using cyclic file.readlines ()

3.5 Large file reading (iterator)

For line in file:

3.6 Positioning

File.tell ()

3.7 Back

File.seek ()

3.8 Refresh

File.flush

3.9 Progress bar

Write memory directly to the hard disk by refreshing

Importsys,time

Foriinrange (100):

Sys.stdout.write ("#")

Sys.stdout.flush ()

Time.sleep (0.1)

4. File operation

4.1 Open mode for simultaneous reading and writing

File.Open ("Name", ' r+ ', encoding= "Utf-8")

This way of reading and writing is to write their own, is written in the last side of the article

File.Open ("Name", ' w+ ', encoding= "Utf-8")

This way is to read their own, according to the position of a bar read, not affected by the position of writing


Python Route 2

Related Article

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.