Python之数值类型

1.  python中支持的数值类型:

1(整形)
```
>>> aInt = 13
>>> print(aInt)
13
>>> print(type(aInt))
<type 'int'>

```

 

17438759847509836949587787(长整形)

```

** python2: 有长整形
>>> aLong = 125653274468735986958609585
>>> print(type(aLong))
<type 'long'>
>>> bLong = 1L
>>> print(type(bLong))
<type 'long'>

 


**python3中: 没有长整形


>>> aInt=1
>>> type(aInt)
<class 'int'>
>>> aLong = 8727398274987398555567985798567777777777985769843
>>> type(aLong)
<class 'int'>
>>> bLong = 1L    
  File "<stdin>", line 1
    bLong = 1L
             ^
SyntaxError: invalid syntax

```


1.23455, 12000000 , 12e6, 1.2e+7, 0.12e+8, 0.012, 1.2e-2(浮点型)

```
>>> aFloat = 1.2
>>> type(aFloat)
<type 'float'>
>>> aFloat = 12e10
>>> aFloat
120000000000.0
>>> type(aFloat)
<type 'float'>
>>> aFloat=12e-10
>>> aFloat
1.2e-09
>>> type(aFloat)
<type 'float'>

```

 

2i+1(复数类型)====x**2>0, x**2=-1

```
>>> aComplex = 2j+3
>>> type(aComplex)
<type 'complex'>


***案例:
>>> aComplex.conjugate()
(3-2j)
>>> aComplex.imag
2.0
>>> aComplex.real
3.0
```

# eFloat = 33e   # 不是浮点数, ae+b(a,b为常量, 代表a*10^b)

# 字符串数据类型

```
>>> aString = "hello"
>>> type(aString)
<type 'str'>

>>> dir(aString)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> help(aString.center)

>>> aString.center(40)
'                 hello                  '
>>> aString.center(40, '*')
'*****************hello******************'
>>> print("学生管理系统".center(50, '-'))
----------------学生管理系统----------------
>>> print("学生管理系统".center(50, '*'))
****************学生管理系统****************

# 布尔值: True(1), False(0)

 

2. 数据类型的转换:

在python中, 所有的数据类型,都可以作为内置函数, 转换数据类型;


```
>>> str(1)
'1'
>>> int(2e-10)
0
>>> complex(2)
(2+0j)
```



3. 如何删除内存中的变量;

```
>>> aFloat
1.2e-09
>>> del aFloat
>>> aFloat
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'aFloat' is not defined
```

***查看帮助: 可以使用什么方法, 实现什么功能?
>>> help(aComplex)

>>> dir(aComplex)
['__abs__', '__add__', '__class__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__eq__', '__float__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__int__', '__le__', '__long__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__', '__pos__', '__pow__', '__radd__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', 'conjugate', 'imag', 'real']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值