Home > Article > Backend Development > How to print variables in python
How to print variables in python?
To print the value of a variable in python, you need to use the print statement. The specific usage method As follows:
Recommended: "Python Tutorial"
1. First, in order to output the value of the variable smoothly, you need to define a variable in the output variable value, such as defining a variable Name a. The definition format is: [a=6] python will automatically define a as an integer variable, which is different from the use of C language.
#2. After the definition is completed, you can use the print statement. The format is as follows [print (variable name)]. Then you can print the value of the variable normally.
3. The complete programming code is as follows:
Extended information:
1. In Python 2, the simplest form of use of the print statement is print A, which is equivalent to executing sys.stdout.write(str(A) '\n').
2. If you use a comma as the delimiter to pass additional parameters (argument), these parameters will be passed to the str() function, and there will be a space between each parameter when printing.
3. For example, print A, B, C is equivalent to sys.stdout.write(' '.join(map(str, [A, B, C])) '\n'). If a comma is added to the end of the print statement, no line break (\n) will be added. In other words: print A is equivalent to sys.stdout.write(str(A)).
4. Starting from python version 2.0, Python has introduced the syntax of print >>, which is used to redirect the file where the print statement finally outputs the string. For example, print >> output, A is equivalent to output.write(str(A) '\n').
The above is the detailed content of How to print variables in python. For more information, please follow other related articles on the PHP Chinese website!