Section 9.12-26, 9.129-26

Source: Internet
Author: User

Section 9.12-26, 9.129-26

1. Use of backslash and escape characters to search online

2. Input

print "how old are you?"age = raw_input()age = raw_input("how old are you?")

Result:

How old are you?

_ (Input)

 

How old are you? _ (Input)

 

print "how old are you?"raw_input(">>")

Result:

How old are you?

>> _

 

3. parameters, unpack, variables

from sys import argva,b,c = argvprint a,b,c

Result (the Object Name Is a. py followed by the parameter 1, 2)

 

A. py 1 2

 

Note that the number of parameter variables must correspond to the number of unincluded packages.

 

4. File Processing

from sys import argvfile1,file2 = argvprint "opening the file "a = open (file2,"w")print "truncating the file "a.truncate()print "two lines:"a.write("abcdef")a.write("\n")a.write('ghijk')a.write(\n)

Result:

Opening the file

Truncating the file

Two lines:

Abcdef

Ghijk

There are more file operation commands

View more information

 

5. Functions

def print_two(*args):    arg1,arg2 = args    print "arg1: %r,arg2: %r")%(arg1,arg2)def print_one(arg1):    print "arg1: %r"%arg1print_two("fan","year")print_one("cool")

Result:

'Fan' 'Year'

'Cool'

def add(a,b):    return a-bprint add(6,2)

Result:
4

 

Note that the function has strict indentation requirements.

 

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.