1、Python 提供了三种类型的可用数值:整型,浮点型,虚数。
2、使用函数type查看数值类型,如type(2.98)。若使用极大或极小(小到一堆小数)的数值时,应该使用可用的模块,后期会阐述。
3、虚数尾部都有一个字母j。
如:>>> a=12j
>>> b=2+4j
>>> a+b
(2+16j)
>>> type(a)
<type 'complex'>
4、文件的使用。将代码写入txt文本后,保存为.py格式。单击File|Open,选择文件保存的路径。单击Run|Run Module
5、在字符串中包含不同的数值,如:
>>> "an integer %d"% 5
'an integer 5'
>>> "a float %f"% 5
'a float 5.000000'
>>> "a float %3f"% 5
'a float 5.000000'
>>> "a float %.2f"% 5
'a float 5.00'
>>> "a float %.03f"% 5
'a float 5.000'
>>> "a larger number %e"% 3.12345e10
'a larger number 3.123450e+10'
>>> "a larger number %.3e"% 3.12345e10
'a larger number 3.123e+10'
6、各类运算,如:
>>> 12+3
15
>>> 3-90
-87
>>> 4*1
4
>>> 4/3
1
>>> 8/2
4
>>> 123456789*987654321
121932631112635269L
>>> 111111111111111111111111111111111111111*77777777777777777777777777
8641975308641975308641975222222222222213580246913580246913580247L
>>> 2e333*23456789
inf
>>> 324/101
3
>>> 324.0/101
3.207920792079208
>>> 65%2
1
>>> 65%3
2
>>> print("%d"% 34)
34
>>> print("%f"% 3.44)
3.440000
>>> print("%f,,%d"% (3.44,3))
3.440000,,3
7、进制,如:
>>> print("%o"% 10)
12
>>> print("%x"% 10)
a
>>> print("%X"% 10)
A