Home  >  Article  >  Backend Development  >  How to print variables in python

How to print variables in python

藏色散人
藏色散人Original
2019-10-18 11:34:556242browse

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.

How to print variables in python

#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.

How to print variables in python

3. The complete programming code is as follows:

How to print variables in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn