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 directory
This 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