Python 编程学习 chapter2 数值与运算
来源:互联网 发布:淘宝怎么赚钱 编辑:程序博客网 时间:2024/06/06 02:09
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
- Python 编程学习 chapter2 数值与运算
- Chapter2 运算方法与运算器
- Python中的数值运算与逻辑运算
- Java多线程编程学习chapter2
- Shell编程---数值运算
- Linux学习之数值运算与运算符
- python 学习笔记 -- 字符串、数值及运算符
- Python基础学习数值运算之内建函数
- 数值运算与运算符
- Python_C2_数值与运算符
- Python学习(一) 数值
- Python数值类型学习
- JavaScript赋值运算与数值运算
- 25 数值运算与运算符
- java语言的科学与艺术 chapter2 编程练习
- 《用Python学习数值分析--插值与拟合》
- Beginning Python Chapter2
- 《编程实践》chapter2
- 使用Hibernate多对一关联表出现的小问题
- Codeforces 526D Om Nom and Necklace kmp+hash
- Android SDK Manger 无法更新问题解决方法 如果有其他更快的网址可以告诉我
- zoj 3640 Help Me Escape(概率DP基础)
- socket中的close和shutdown区别
- Python 编程学习 chapter2 数值与运算
- 日拱一卒(三十三)
- 【贪心专题】POJ 3258 River Hopscotch (最大化最小值 贪心+二分搜索)
- c&c++反汇编与逆向分析学习笔记(3)--基本数据类型表现形式
- 第三节 Informatica 体系架构之 Service Manager 服务管理器
- 用结构体创建静态链表
- 关于Qt下报错没有mysql驱动问题
- SpringMVC视图解析器
- cin/cout 比 scanf/printf 慢吗