python 变量
来源:互联网 发布:radio flyer淘宝 编辑:程序博客网 时间:2024/06/01 10:24
Python 使用 “=” 做赋值操作符
变量名 = 值
变量名:必须是大小写英文,数字或_的任意组合,且不能以数字开头
另外python 内置关键字不能做为变量名
值可以是任意数据类型
例:
a = 5
b = 'helloworld'
c =[1,2,3,4,]
d = {'zhang':23,'li':18}
我们来执行一下看
print(type(a))print(type(b))print(type(c))print(type(d))
显示
<class'int'><class'str'><class'list'><class'dict'>
从python的内部原理来了解变量的话,这个= 的操作实际上是一个引用的概念,这里延伸一下多重赋值的概念,通过id()à[id用来查看对象的内存地址]来证明这一点。
a = 5b = ac = d = 6
print("a:",id(a))print("b:",id(b))print("c:",id(c))print("d:",id(d))
输出结果如下
a:502387216b:502387216c:502387232d:502387232
下面咱们再来通过一张图来说明这一点
多重变量实际上只是多了一个引用关系,并不会在内存中申请一块新的地址使用
多元赋值
a,b,c = 1,2,'hello world'
结果
print(a)print(b)print(c)
12hello world
1 0
- python:变量
- Python变量
- python变量
- Python-变量
- python 变量
- python变量
- python变量
- Python变量
- Python 变量
- Python 变量
- Python 变量
- python变量
- python变量
- Python变量
- Python变量
- Python 变量
- python变量
- Python变量-下划线,私有变量
- Making Fabric Play Nice with RubyMotion
- Okio简化处理I/O操作原理
- android:强大的图片下载和缓存库Picasso
- odoo config配置信息
- 一元多项式相加(C语言实现)
- python 变量
- MFC中绘制动态曲线
- 《python》学习笔记(Day1),创建python发布
- PHP框架 Yii framework 用yiic命令时提示“php.exe”不是内部或外部命令,也不是。。。。怎么解决?
- MySQL索引背后的数据结构及算法原理
- java入门学习(10)—抽象类
- Material Design for Developers(一)概述
- 利用GDB调试多线程core文件
- Objective-C与JavaScript交互的那些事