python 无符号整数_Python中的有符号和无符号整数数组

python 无符号整数

An array can be declared by using "array" module in Python.

可以通过在Python中使用“数组”模块来声明数组

Syntax to import "array" module:

导入“数组”模块的语法:

    import array as array_alias_name

Here, import is the command to import Module, "array" is the name of the module and "array_alias_name" is an alias to "array" that can be used in the program instead of module name "array".

在这里, import是导入Module的命令, “ array”是模块的名称, “ array_alias_name”“ array”的别名,可以在程序中使用它而不是模块名称“ array”

Array declaration:

数组声明:

To declare an "array" in Python, we can follow following syntax:

要在Python中声明“数组” ,我们可以遵循以下语法:

    array_name   =   array_alias_name.array(type_code, elements)

Here,

这里,

  • array_name is the name of the array.

    array_name是数组的名称。

  • array_alias_name is the name of an alias - which we define importing the "array module".

    array_alias_name是别名的名称-我们定义了导入“ array module”的名称

  • type_code is the single character value – which defines the type of the array elements is the list of the elements of given type_code.

    type_code是单个字符值–定义数组元素的类型是给定type_code的元素列表。

声明有符号和无符号整数数组 (Declaring Signed and Unsigned Integer Array)

Signed Integer is defined by using type_code "i" (small alphabet "i") and it contains negative and posited integers.

通过使用type_code “ i” (小写字母“ i” )定义带符号整数 ,它包含负整数和正整数。

Unsigned Integer is defined by using type_code "I" (Capital alphabet "I") and it contains only positive integers.

通过使用type_code “ I” (大写字母“ I” )定义无符号整数,并且它仅包含正整数。

Examples to declare and initialize "unsigned" and "signed" integer array in Python:

在Python中声明和初始化“ unsigned”和“ signed”整数数组的示例:

# unsigned integer array 
a = arr.array ("I", [10, 20, 30, 40, 50])
# signed integer array 
b= arr.array ("i", [10, -20, 30, -40, 50])

Program:

程序:

# importing array class to use array 
import array as arr

# an unsigned int type of array 
# declare and assign elements 
a = arr.array ("I", [10, 20, 30, 40, 50] )
# print type of a 
print ("Type of a: ", type (a))
# print array 
print ("Array a is: ")
print (a)

# a signed int type of array 
# declare and assign elements 
b = arr.array ("i", [10, -20, 30, -40, 50] )
# print type of a 
print ("Type of b: ", type (a))
# print array 
print ("Array b is: ")
print (b)

Output

输出量

Type of a:  <class 'array.array'>
Array a is:
array('I', [10, 20, 30, 40, 50])
Type of b:  <class 'array.array'>
Array b is:
array('i', [10, -20, 30, -40, 50])


翻译自: https://www.includehelp.com/python/signed-and-unsigned-integer-arrays-in-python.aspx

python 无符号整数

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值