Learn python with socratica [My notes] - part 4 - Numbers_py_3

Lesson 5

上节课使用python2实验了很多数据类型,本节来看看python3做了哪些改变,有什么不同之处。

int类型

# Let's begin!

# Types of Numbers: int, float, complex

a = 496 # This is a perfect number
type(a) # get a's type
int

a # get a's value
496

print(a) # print a's value
496

float类型

# define float number e
e = 2.71821291

# To confirm it is a float, get its type.
type(e)

float

complex类型

1
2
3
4
5
6
7
8
9
10
11
12
13
# define complex number z
z = 6 - 1.4j

# check its type
type(z)
complex

# get its's real part and imag part
print(z.real)
print(z.imag)

6.0
-1.4

和python2一样,都是用float类型来表示实部和虚部的。

Conclusion

1
2
>>> print("Numbers in python2 and python3 are no difference.")
Numbers in python2 and python3 are no difference.

Youtube source:
https://www.youtube.com/watch?v=bY6m6_IIN94&list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-