Integrated programming mini-project for "Local data acquisition"

Source: Internet
Author: User

(1) Create a file blowing in the Wind.txt, the content is: #问题非原创
How many roads must a man walk down
Before they call him a mans
How many seas must a white dove sail
Before she sleeps in the sand
How many times must the cannon balls fly
Before they ' re forever banned
The answer my friend is blowing
The answer is blowing
(2) Insert the song name "Blowin ' in the Wind" at the head of the file
(3) Insert the singer's name after the song name "Bob Dylan"

(4) Add the string "1962 by Warner Bros. Inc" At the end of the file.


>>> f = open (R ' blowing in the Wind.txt ', ' W ') >>> f.write (' What many roads must a man walk down\nbefore the Y call him a man\nhow many seas must a white Dove Sail\nbefore she sleeps in the sand\nhow many times must the cannon ball s Fly\nbefore they\ ' re forever banned\nthe answer my friend is blowing in the wind\nthe answer was blowing in the wind ') 278 >>> f.close () >>> f = open (R ' blowing in the Wind.txt ') >>> line = F.readlines ()  # Reads the data one line at a time from the source file and returns it as a list. >>> Line.insert (0, "Blowin ' in the wind\n") >>> Line.insert (1, ' Bob dylan\n ') >>> line.append ( ' \n1962 by Warner bros.inc. ') >>> f.close () >>> f = open (R ' blowing in the Wind.txt ', ' W ') >>> f.writelines (line) >>> F.close ()

Add: List

with len () function to get the number of list elements;

Use an index to access the elements of each position in the list, remembering that the index is from the 0 start: list[0]

list append element to end: List.append ()

1 location: List.insert (1, Element)

Delete the element at the end of the list with pop () method: List.pop ( )

Delete the element at the specified position, using the pop (i) method, where i is the index location: List.pop (i)

Replacing an element with another element can be directly assigned to the corresponding index position: list[1] =


Integrated programming mini-project for "Local data acquisition"

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.