在Python中将字符串转换为长整型
Python定义了类型转换函数来直接将一种数据类型转换为另一种数据类型。本文旨在提供有关将字符串转换为长字符串的信息。
将字符串转换为长
long 是具有无限长度的整数类型值。通过将字符串转换为 long,我们将字符串类型的值转换为 long 类型。在 Python3 中,int 默认升级为 long,这意味着Python3 中的所有整数都是长整数。因此我们可以在Python中使用 int() 将字符串转换为 long 。
句法 :
int(string, base)
范围 :
string : consists of 1's and 0's
base : (integer value) base of the number.example 1
示例 1:
Python3
a_string = "123"
print(type(a_string))
# Converting to long
a_long = int(a_string)
print(a_long)
print(type(a_long))
Python3
a='0x'
arr0 = '00000018000004000000000000000000'
arr1 = '00000000000000000000000000000000'
arr2 = 'fe000000000000000000000000000000'
arr3 = '00000000000000000000000000ffffff'
data = a+arr0+arr1+arr2+arr3
print(data)
print(type(data))
# Converting to long
data1 = int(data, 16)
print(type(data1))
输出:
123
示例 2:
Python3
a='0x'
arr0 = '00000018000004000000000000000000'
arr1 = '00000000000000000000000000000000'
arr2 = 'fe000000000000000000000000000000'
arr3 = '00000000000000000000000000ffffff'
data = a+arr0+arr1+arr2+arr3
print(data)
print(type(data))
# Converting to long
data1 = int(data, 16)
print(type(data1))
输出:
0x0000001800000400000000000000000000000000000000000000000000000000fe00000000000000000000000000000000000000000000000000000000ffffff