Python 基础02
来源:互联网 发布:淘宝店铺星级靠谱么 编辑:程序博客网 时间:2024/05/21 13:54
变量不需要声明
Python的变量不需要声明,你可以直接输入:
>>>a = 10
那么你的内存里就有了一个变量a, 它的值是10,它的类型是integer (整数)。 在此之前你不需要做什么特别的声明,而数据类型是Python自动决定的。
>>>print a
>>>print type(a)
那么会有如下输出:
10<type 'int'>
这里,我们学到一个内置函数type(), 用以查询变量的类型。
回收变量名
如果你想让a存储不同的数据,你不需要删除原有变量就可以直接赋值。
>>>a = 1.3
>>>print a,type(a)
会有如下输出
1.3 <type 'float'>
我们看到print的另一个用法,也就是print后跟多个输出,以逗号分隔。
基本数据类型
a=10 # int 整数
a=1.3 # float 浮点数
a=True # 真值 (True/False)
a='Hello!' # 字符串
以上是最常用的数据类型,对于字符串来说,也可以用双引号。
(此外还有分数,字符,复数等其他数据类型,有兴趣的可以学习一下)
总结
变量不需要声明,不需要删除,可以直接回收适用。
type(): 查询数据类型
整数,浮点数,真值,字符串
0 0
- Python 基础02
- Python基础:02数字
- Python 基础练习02
- Python语言基础-02
- python基础入门 02
- Python学习笔记 02 Python基础
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02—变量
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Python基础02 基本数据类型
- Swift中的函数
- 添加特殊U盘filter后,virtualbox不能启动
- 树的非递归遍历
- Linux光标操作
- 自定义ShareSDK分享平台界面
- Python 基础02
- 调试 acf 的时候发现问题
- Please ensure that adb is correctly located at 问题解决
- GitHub 优秀的 Android 开源项目
- Python 基础03
- Seeking precision function
- Hibernate懒加载解析
- Layout management in wxWidgets
- iOS 在UILabel显示不同的字体和颜色(转)