Beginners Learn Python Notes

Source: Internet
Author: User

1. Modules: three methods of invocation


1. A python file written in vim * *, using Import * *, can be called directly in interactive mode

2. Call a function inside the module:

From module name in function name

3. Shorten the module name to call:

Import module formerly known as new name


2. Python-based storage directory for things:

'/usr/lib64/python2.6/site-packages ',

3. Write the file to disk:

A=file (' File name ', ' W ') ' Create new file '

A.write (' file content 1 file Content 2 ') ' Write file contents '

A.close () "Close file"

Append file contents:

A=file (' File name ', ' a ') ' Append file Contents '

A.write (' \ n file content 1 file Contents 2 ') ' Write content ' \ n ' newline

A.close () Close file

View of the file:

A=file (' filename ') ' Open file '

A.read ()"Viewing files in a read-only manner"

A.read () reads once and then reads the second time as empty, because memory frees it. If you want to save it for a long time, you have to write it into a variable and save it in memory. ' That is f=a.read () '

For line in A.readlines ():p rint line.split () [' 0 '],---"0 represents the first column"

A.readlines () reads the display as a string

**.split () Converts a string into a list


4. Delete the character set:

S.strip (RM) Remove the characters from the beginning and end of the s string in the RM delete sequence

When RM is empty, the default is to remove whitespace characters (including ' \ n ', ' \ R ', ' \ t ', ')


This article is from the Linux OPS blog, so be sure to keep this source http://9162199.blog.51cto.com/9152199/1659441

Beginners Learn Python Notes

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.