Python basics [Article 4] parameters, python Article 4 parameters

Source: Internet
Author: User

Python basics [Article 4] parameters, python Article 4 parameters

The program cannot avoid the need for some parameters to support the program. How can the program receive parameters? Here, the sys. argv [] Method of the sys module is used to obtain parameters.

1. Usage:

Import sys // detailed description of the imported sys module later

Sys. argv [tage] // obtain the value based on the subscript of the parameter.

(Note: The above tage is a subscript, where the program itself is 0, that is, sys. argv [0], and the parameters after the script are in turn)

 

2. Example:

// Script content

# Vim tmp. py
#! /Usr/bin/env pythonimport sysprint sys. argv [0] print sys. argv [1] print sys. argv [2]

 

// Execution result

# Python tmp. py string1 string2tmp. pystring1string2

 

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.