码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习字典.基础三

时间:2017-08-30 17:13:04      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:需要   分割   student   类型   bin   value   学习   python   strong   

元组
    Python的元组与列表类似,不同之处在于元组的元素不能修改。
  元组使用小括号,列表使用方括号。
  元组中要定义的元组中只有一个元素需要再元素后面加逗号,用来消除数学歧义。例 t=(1,)
 
 
字典
  字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号{}中。
  键必须是唯一的,但值则不必(只可以取任何数据类型,但键必须不可变)
例子:
#coding=utf-8
#!/usr/bin/python
 
student={1:‘ja‘,2:‘qw‘,3:‘as‘}
print (student[1])
 
student[4]=‘zxc‘ #新增的键值对
print (student)
 
student[2]=‘we‘ #修改字典值
print (student)
 
del student[2] #删除字典值键对
print (student)
 
student.clear()
print (student) #清除字典全部键值
 
del student #删除字典
print (student)
 
 

Python学习字典.基础三

标签:需要   分割   student   类型   bin   value   学习   python   strong   

原文地址:http://www.cnblogs.com/uu-chloe/p/7453946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!