Here we create a python (pytest) script for the Learning test (this file is not explained much later), this file must have the execution permission of the HA
1. Create Pytest and give Execute permissions
Touchchmod +x pytest
2. Basic Output "Print"
[Email protected]_server py]# vim pytest
# Specify python executable path # !/usr/bin/python # Print a string Print ' This is python ' # Print an Operation Print ' 100+200 = ', 100+200
Run pytest to view output results
[Email protected]_server py] # ./pytest
is python100+200 = 300
This simple output should be wooden what's the matter,
Here's a question for you:
Do not know everyone noticed that there is no print ' 100+200 = ', 100+200 "," This symbol I tested under this symbol must be added! The intent is that the connection string and command are also whitespace outputs.
Another point is that the format of the Python3 version of print is changed in the following format
>>>Print ("string")
3.python basic Inputs input ()/raw_input ()
The basic output is simple, just print, so how do I read the input? Python reads based on the built-in function input, raw_input
The format is as follows:
[number]=raw_input (' string ') [number]=input (' string ')
The number above is the variable string for the hint string raw_input/input will output the read value to
Since raw_input and input can read input, what is the difference between them?
Input: You can enter a valid expression, such as input 1+2 and it will also recognize the int format, that is, you do not need a conversion to enter the number of operations
Raw_input: You can enter any numeric value without error, the input value is recognized as a string, that is, you need to enter the number of conversion to perform operations
For example, let's take a look at the following:
3.1. Input
Example: Enter 1+2 to view output results
# !/usr/bin/pythonnumber1=input ('pleaseinput your number1:')Print Number1
[Email protected]_server py]#./Pytestplease input your number1:1+23
3.2, Raw_input
Example: Run a script to prompt for a value, and then output the value
[[Email protected]_server py]# vim Pytest # !/usr/bin/python Number1=int (raw_input ( " please input your Number1: " =int (raw_ Input ( " please input your number2: ' ') print '
[Email protected]_server py]#./Pytestplease input your number1:Pleaseinput your number2: Ten
4. String symbol Quotes
In Python there are three types of quotes that you can use, namely:
Single quotation marks ('), double quotation marks (""), three quotation marks ("" "" "")
Three ways are basically almost all of the output string below we look at three kinds of output effects
>>> print ( " this is test txt " ) this is test txt >>> print ( Span style= "color: #800000;" > " this is Test txt " ) This is test txt >>> Span style= "color: #0000ff;" >print ( this istest txt "" " " this is test txt
You can see the single and double quotation marks as the same as the three quotation marks compare personality points
Let's look at the difference between the three quotes.
4.1. Single and double quotes are interchangeable differences are not too large, their difference is when the two symbols mixed, as shown in the following example
>>>Print('Test This'S')syntaxerror:invalid Syntax>>>Print("Test this ' s") Test this's>>>Print(" This is"Test"") Syntaxerror:invalid Syntax>>>Print('This is "test"') This is "Test"
It is clear from the above example that single quotes can no longer contain single quotes, double quotation marks can no longer contain double quotes (unless escaped with the escape character "\"), or Python is not recognized as the beginning and end of single and double quotation marks.
4.2. Three quotation marks
Can wrap, suitable for output text
Note: The problem of line wrapping in fact, single and double quotation marks can be done only in a different way, the single quotation/double quotation marks line is as follows:
Add "\ n"
Print ('this is\ n Test'istest
Ok! Above we learned the basic Python environment and python input and output let's do a case study to test our results!
Case:
Case: Execute the script enter two numbers and add the number to the result to print, the first number is required to use the function input through the expression, the second value requires the use of raw_input
[Email protected]_server py]#Vim Pytest#!/usr/bin/python#use input to get the first valueNumber1=input ('Please input your number1:')#use Raw_input to get the second value and int to start the Huawei IntegerNumber2=int (Raw_input ('Please input your number2:'))#print out the results of two valuesPrint 'sumber=', number1+number2#execute script to view execution results[Email protected]_server py]#./pytestPlease input your number1:1+1516Please input your number2:16Sumber= 32
Ok! What about the script contents and the output results? A bit of a sense of accomplishment!
Python Basics "Third" input and output