python 整数 八进制_通过在Python中分配八进制值来创建整数变量

本文介绍如何在Python中创建整数变量并以八进制格式分配值。通过使用0o后缀,我们可以指定数值为八进制,并使用oct()函数以八进制格式打印值。
摘要由CSDN通过智能技术生成

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 整数 八进制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值