Python Basic formatted output

Source: Internet
Author: User

A= ' This is a '

B=a.replace (' A ', ' B ') string substitution

C= ' This is%s%s '% (' my ', ' Apple ')

D= ' This is {} {} '. Format (' My ', ' Apple ')

E= ' This is {1} {0} '. Format (' Apple ', ' my ') formatted output, output order

F= ' This is {whose} {fruit} '. Format (fruit= ' Apple ', whose= ' my ')

G= ' This is% (whose) s% (fruit) s '%{' fruit ': ' apple ', ' whose ': ' My '} Another formatted output, followed by a dictionary that corresponds to the previous key's value%s, defined by the key% after the value

============================

Read file

1, f=open (' filename ', ' W ')

F.write (' This is file ')

F.close

2. F=file (' filename ', ' r ')

F.read (20)

F.seek (0) back to the first position of the file cursor

F.close ()

3. Import Linecache

Linecache.getline (' filename ', line number)

A=linecache.getlines (' filename ')

Print A is stored in the list

Python Basic formatted output

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.