python定义整数
Define an integer value in a variable and print it in Python.
在变量中定义一个整数值,然后在Python中打印出来。
Its very simple todeclare a variable and define an integer value to it, there is no need to define any type of keyword to make the variable an integer, we have to just assign an integer value and variable is able to store and then we can print it.
声明变量并为其定义整数值非常简单,无需定义任何类型的关键字即可使变量成为整数,我们只需分配一个整数值即可存储变量,然后我们可以打印它。
Syntax:
句法:
variable_name = value
Example:
例:
If we want to assign10to a variable named num, the statement will be:
如果我们想将10分配给名为num的变量,则该语句将为:
num = 10
Program:
程序:
# Python program to define an # integer value and print it # declare and assign an integer value num = 10# print num print "num =",num # print using formatprint "num = {0}".format(num)# assign another valuenum = 100# print num print "num =",num # print using formatprint "num = {0}".format(num)
Output
输出量
num = 10num = 10num = 100num = 100
Note:In this program, we also used format() Method to print the value as string formatted, read more about, String.format() Method.
注意:在此程序中,我们还使用format()方法将值打印为字符串格式,请阅读有关String.format()方法的更多信息。
翻译自: /python/define-an-integer-value-and-print-it.aspx
python定义整数
如果觉得《python定义整数_Python | 程序定义一个整数值并打印》对你有帮助,请点赞、收藏,并留下你的观点哦!