python 整数 八进制
The task is to create integer variables and assign values in octal format.
任务是创建整数变量并以八进制格式分配值 。
八进制值分配 (Octal value assignment)
To assign value in octal format to a variable, we use 0o suffix. It tells to the compiler that the value (suffixed with 0o) is an octal value and assigns it to the variable.
要将八进制格式的值分配给变量,我们使用0o后缀。 它告诉编译器该值(后缀0o )是一个八进制值,并将其分配给该变量。
Syntax to assign an octal value to the variable
为变量分配八进制值的语法
x = 0o12345678
通过分配八进制值来创建变量的Python代码 (Python code to create variable by assigning octal value)
In this program, we are declaring some of the variables by assigning the values in octal format, printing their types, values in decimal format and octal format.
在此程序中,我们通过以八进制格式分配值,打印其类型,十进制格式和八进制格式的值来声明一些变量。
Note: To print value in octal format, we use oct() function.
注意:要以八进制格式打印值,我们使用oct()函数 。
# Python code to create variable
# by assigning octal value
# creating number variable
# and, assigning octal value
a = 0o1234567
b = 0o7654321
c = 0o1745
d = 0o100
e = 0o123
# printing types
print("type of the variables...")
print("type of a: ", type(a))
print("type of b: ", type(b))
print("type of c: ", type(c))
print("type of d: ", type(d))
print("type of e: ", type(e))
# printing values in decimal format
print("value of the variables in decimal format...")
print("value of a: ", a)
print("value of b: ", b)
print("value of c: ", c)
print("value of d: ", d)
print("value of e: ", e)
# printing values in octal format
print("value of the variables in octal format...")
print("value of a: ", oct(a))
print("value of b: ", oct(b))
print("value of c: ", oct(c))
print("value of d: ", oct(d))
print("value of e: ", oct(e))
Output
输出量
type of the variables...
type of a: <class 'int'>
type of b: <class 'int'>
type of c: <class 'int'>
type of d: <class 'int'>
type of e: <class 'int'>
value of the variables in decimal format...
value of a: 342391
value of b: 2054353
value of c: 997
value of d: 64
value of e: 83
value of the variables in octal format...
value of a: 0o1234567
value of b: 0o7654321
value of c: 0o1745
value of d: 0o100
value of e: 0o123
翻译自: https://www.includehelp.com/python/create-integer-variable-by-assigning-octal-value.aspx
python 整数 八进制