Python 编程学习 chapter2 数值与运算

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值