Python syntax two

Source: Internet
Author: User

1.raw_input input

2. If you want to see the use of a keyword, you can enter Pydoc raw_input at the command line.

If it's windows, then try Python-m pydoc raw_input

3. Parameters, unpacking, variables

Run the following code, enter $ python ex13.py first 2nd 3rd

From sys import ARGV

Script, first, second, third = argv #argv包含了所有传递给它的参数

Print "The script is called:", script #ex13. py

Print "Your first variable is:", first #first

Print "Your second variable is:", second #2nd

Print "Your third variable is:", third #3rd

4. Tips and Delivery

such as: Likes=raw_input (' Please enter the name you like ')

Or: prompt= ' >>> '

Likes=raw_input (Prompt)

The above notation indicates the prompt in front of the input.

5. close– Close the file. Save it with your editor's file. a meaning.

read– reads the contents of the file. You can assign the result to a variable.

readline– reads a line in a text file.

truncate– Empty The file, use this command with care.

Write (stuff) – writes stuff to the file.

--------------------------------------------------------

#-*-Coding:utf-8-*-
Filename=raw_input ("Please enter your file name:")
Filetxt=open (filename, ' W ') #因为要进行写入参数, so you need to identify the W when you open the file
print "Deleting original file Contents"
Filetxt.truncate ()
Print "Delete Complete"
Filecontent=raw_input ("Please enter a new content:")
Filetxt.write (filecontent)
Filetxt.write ("\ n")
Filetxt.write (filecontent)

Filetxt.close ()

-----------------------------------------

In addition to ' W ', there is ' r ' for reading, ' A ' means append

If only the open (filename) is written, then the ' R ' mode is used by default.

Python syntax two

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.