4.python Module

Source: Internet
Author: User

python string

First, Notes

Comments in Python divided into single-line comments and multiline comments

(1) single-line comment : to add "#" to the front of the statement

Example:

#!/usr/bin/env python

A = 123

Print a

#print A

#print A

#print A

The results of the implementation are as follows:

[email protected] ~]# python a.py

123

(2) multi-line Comment : You can use 3 pairs of single quotation marks (such as "' Comment content") or 3 pairs of double quotation marks (e.g. "" "" "" ")

Example:

#!/usr/bin/env python

A = 123

Print a

Print a

‘‘‘

Print a #第三四行被注释掉了

Print a

‘‘‘

Execution results are as follows

[email protected] ~]# python a.py

123

123

Results only two lines are printed

The difference between single quotation marks, double quotation marks, and three quotation marks

If you output multiple lines of file content, either single quotation marks or double quotes are not output correctly. Will error

When you export multiple lines of content correctly and wrap them, you must use three quotation marks.

If you are using newline symbols \ The printed string is on one line, not multiple lines.

\ n : equivalent to carriage return

\ t: Indent in

Use 3 quotation marks to execute the result as follows

#!/usr/bin/env python

print ' ABC

123

Hello word!

‘‘‘

[email protected] ~]# python a.py

Abc

123

Hello word!

Use line break \ Execute structure as follows

#!/usr/bin/env python

print ' ABC \

123 \

Hello word!\

‘

[email protected] ~]# python a.py

ABC 123 Hello word!

Third, python Module

The module is the system-written code in Python, which I can call directly. The contents of the module are executed after the call.

Ways to import Modules:

1. Import module name

Example:

>>> import os #导入了系统模块os

2. from module name import function name # Import a function in the module

Example:

>>> from OS import system #导入了os模块中的system函数.

>>> system (' DF ') #导入了这个函数后, we can invoke the systems command.

Filesystem 1k-blocks used Available use% mounted on

/dev/sda3 18475900 4350884 13186472 25%/

Tmpfs 506176 506100 1%/DEV/SHM

/DEV/SDA1 99150 29998 64032 32%/boot

/dev/sr0 4363088 4363088 0 100%/media/centos_6.5_final

3. Set the alias for the module name

Import Module name as Alias

4. Use the TAB key to view the script for the module function

4.python Module

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.