十六进制整数以“0x”或“0X”开始''' bInt=010101dInt=84455555oInt=075hInt=0xabcprint"The binary of the standard integer:",bInt print"The decimal of the standard integer:",dInt print"The octal of the standard integer:",oInt print"The hexadecimal of the standard integer:",hInt print''' ...
>>>x = set('abcde') #以下测试均在python2.6 中运行 >>>y = set('bdxyz') #python2.6中创建集合 >>>x set(['a','b','c','d','e']) >>> >>>'e' in x #运算符测试 True >>>z = x.intersection(y) #x & y #方法测试 >>>z set(['b','d']) >>>z.add('spam') >>>...
前面讲到了,我们可以使用变量来指定不同的数据类型,对网工来说,常用的数据类型的有字符串(String), 整数(Integer), 列表(List), 字典(Dictionary),浮点数(Float),布尔(Boolean)。另外不是很常用的但需要了解的数据类型还包括集合(set), 元组(tuple)以及空值(None),下面一一举例讲解。
[python] view plain copy import decimal # Set up a context with limited precision c = decimal.getcontext().copy() c.prec = 3 # Create our constant pi = c.create_decimal('3.1415') # The constant value is rounded off print 'PI :', pi # The result of using the constant uses the ...
processed_files = []fordollar_iindollar_i_files:# Interpret file metadatafile_attribs = read_dollar_i(dollar_i[2])iffile_attribsisNone:continue# Invalid $I filefile_attribs['dollar_i_file'] = os.path.join('/$Recycle.bin', dollar_i[1][1:]) ...
>>> def set_bit(value, bit_index): ... return value | (1 << bit_index) ... >>> set_bit(0b10000000, bit_index=5) 160 >>> bin(160) '0b10100000' 掩码保留所有原始位,同时在指定索引处强制执行二进制 1。如果该位已经被设置,它的值就不会改变。
Python 里面有自己的内置数据类型 (build-in data type),基本数据类型包含三种,分别是整型 (int),浮点型 (float),和布尔型 (bool) 1.1 整型 整数(integer) 是最简单的数据类型,和下面浮点数的区别就是前者小数点后没有值,后者小数点后有值。 a = 205 print(a, type(a)) 1. 2. 205 <class 'int'>...
information, type 'help <item>', where <item> is one of the following topics: AUTO_INCREMENT BIGINT BINARY BIT BLOB BLOB DATA TYPE BOOLEAN CHAR BYTE DATE DEC DECIMAL DOUBLE DOUBLE PRECISIONENUM FLOAT INT INTEGER LONGBLOBLONGTEXTMEDIUMBLOB MEDIUMINT MEDIUMTEXT SET DATA TYPE SMALLINT TEXT TIME...
'__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'as_integer_ratio', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_byte...
In this script, we're going to set the bits from left to right using binary bit shifting in the range defined by our CIDR. We use a for loop to iterate through this range and do the math. That math, in words, is: Take the mod of the current iterator and eight. Subtract it from...