Python learning notes 1, input and output, and python learning notes

Source: Internet
Author: User

Python learning notes 1, input and output, and python learning notes

Output: Useprint()Add a string to the brackets to output the specified text to the screen. For example, output'hello, world', Use the code to implement the following >>> print ('hello, World ')

It can also be multiple strings, with a comma in The middle linking '; Code implementation is as follows> print ('the quick bronw Fox', 'jumps over', 'the lazy dog ')

Note! If a comma is encountered during output, a space is output.

Print () can also print numbers and computation results. To make the output more elegant, you can write >>> print ('2014 + 100 = ', 200 + 100)

Input: python uses the input () function. For example, the input name is not directly output, but saved to the name variable. When we want to access it, we will directly write the name to find the corresponding content;

To edit the python code in the text editor, run the cmd command to find the directory for saving the py file, and then run python hello. py;

If an error is prompted:

python: can't open file 'hello.py': [Errno 2] No such file or directoryThis indicates that the file does not exist, that is, the path is incorrect;

Then proceed with the above input, and write the code directly in the text editor this time,
Name = input ()
Print ('hello', name)
The program executes the first input function, that is, waiting for the input. After a name is input, the program executes the output function. The result is

Of course, there can be a string of characters in the input function as the prompt. For example, input ('Please enter your name') will first output a prompt and then wait for the input.

Here is another knowledge point:
The command line mode and the python interaction mode, the execution of the python program in the command line mode are different from the execution of the python program in the interactive mode, for example, the Direct Writing in the interactive mode, 100 + 200 after the press enter, 300 will be printed directly, but if you write this program in the text editor
If you execute the command line, nothing will be output. to output the result, you must use the print function;




-- Refer to Liao Xuefeng's official website

Related Article

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.