python a basic data type (integer type and Boolean)

Integer (int)

Integer keywords Python is represented by int; Integer in a computer for calculating and comparing the

In python3 are all integer int. However, if a large amount of data. Python2 will be used in the long type.

Long type integer operation may be performed in the absence of python3:

Integer plus 1.1

a = 10
b = 20
print(a + b)
结果:
30

1.2 Save integer

a = 10
b = 20
print(b - a)
结果
10

1.3 integer multiplication

a = 10
b = 20
print(a * b)
结果:
200

1.4 In addition to integer

a = 10
b = 20
print(b / a)
结果:
2.0
# 注意点:当我们使用Python3的时候我们除法获取到时浮点数,也就是小数,但是使用Python2的时候使用除法获取的就是整数

Integers divisible 1.5

a = 10
b = 20
print(b // a)
结果:
2

1.6 of integers modulo

a = 5
b = 2
print(a % b)
结果:
1

1.7 integer power (power)

a = 5
b = 2
print(a ** b)
结果:
25

Precautions: the presence of long (long integer), but in the absence of Python2 Python3 in the long (long)

We often say that there is in the form of numbers are decimal numbers indicate there are many, we would simply say today about the decimal and binary numbers

How is conversion between them, let's look at the binary decimal conversion, divided by the use of a method, for example, the decimal number 15 in binary we want to know is how much it is 15 divided by 2 and then get him the remainder from the bottom up the remainder fight together, it is to use the following method

image-20190622185507122

We now know how to convert decimal numbers into binary, then look at how to convert binary to decimal.

We use 110 001 to, for example, want to get into this binary number is then converted to decimal now proceed as follows

接下来的计算我们就从右向左计算,用最右侧的数乘以2的0次方,依次向左推
1*2**0 + 0*2**1 + 0*2**2 + 0*2**3 + 1*2**4 + 1*2**5    换算下来就是
  1    +    0   +   0    +   0    +   16   +   32 =  49

We use this approach converts the number will be able to count binary to decimal

Boolean value

bool()布尔值
print(bool(1))#非零为True,零为False
print(bool("123"))#空字符串为Flase,不为空字符串为True

* ** data type conversion

str int conversion

a=int('33')
print(a)#结果33#只有要转换的字符串是数字的时候才能转换

int conversion str

n=str(56)
print(n)#结果"56"

bool convert str

bool值不为空就是True,空就是False
b=str(True)
print(b)#结果true

bool int conversion

b=int(True)
print(b)#结果1

Guess you like

Origin www.cnblogs.com/luckinlee/p/11619758.html