Python tips for using

Source: Internet
Author: User

1. Embed double and single quotes in a string

use the escape character "\"

Example:

2. Print Numbers:0001~0009 This form

Example:

3. strip () Action string method in Python

Example:str= "Hello hai haisljkdj"

1) Str.strip (): Remove the string header and trailing spaces and \ n and \ t

2) str.strip (' Hai '): Delete the string from the beginning or the end with the Hai character

3) Str.rstrip (): Delete trailing space

4) Str.lstrip (): Delete the beginning of the space

4. Take the string apart into the list

5. use split to split the string

Example:

6. OS ( renaming, judging existence, getting address )

Example:

Import OS

Os.rename (' 12.txt ', ' 456.txt '): Change file name

Os.system ("Copy 1.txt 2.txt"): Copying Files

Os.path.exists (' 1.txt '): Determine if the file exists

Os.path.exists (' D:\\test '): Determine if a folder exists

OS.GETCWD (): Gets the path of the current file

Os.path.join ("C:\\test", "Log.txt"): Connect two addresses together

7. Python Delete List element method

Example:

Python tips for using

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.