Python 编程学习 chapter2 数值与运算
2015-04-05 22:15
417 查看
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
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
相关文章推荐
- Python 编程学习 chapter 3 变量
- Python基础学习数值运算之内建函数
- Python 编程学习 chapter 1 编程基础与字符串
- Python 核心编程笔记_Chapter_5_Note_1 数据类型及相关运算
- Python3 基础学习之数值简单运算
- python核心编程学习(二)
- python核心编程学习(三)
- Python学习(一) 数值
- 学习python 第一季:编写简单乘法运算题
- SQL学习之连接符,数值运算,函数
- 【python学习】之二、函数式编程
- python核心编程学习(一)
- python 核心编程学习笔记(第4章) 对应Let's-python视频第5集
- python 网络编程学习: 1 初识 SOCKET
- python 学习1阶段 编写简单乘法运算
- python学习第十四章——网络编程
- python核心编程学习(四)
- python核心编程学习(第四章)
- python 核心编程学习笔记(第3章) 对应Let's-python视频第4集
- Lemon的Python学习笔记-数值和运算符