python的四种数据结构浅析

python是什么?python

1:一门流行的脚本语言。web

2:在web开发、网络开发、脚本运用使用许多。编程

为何要学习脚本语言?网络

1:由于软件中不少功能须要工具化、傻瓜化。数据结构

python的四种数据结构app

1:列表ide

#定义一个列表工具

shopList=['zl','maer','zhengl']学习

#获取列表的长度设计

print len(shopList)

#遍历列表

 

for i in shopList:

    print i

#向列表中添加元素

shopList.append('tgc')

#经过下标遍历列表

print shopList[1]

2:元组

#定义元祖

people=('zl','tgc','zhyl')

#获取元组的长度

print len(people)

#将元组做为一个对象传入另外一个元组

add_people=('maer','junw',people)

#获取add_people元组的第三个对象的第二个对象

print add_people[2][1]

#经过元组来遍历数据

 

age=22

username='zlzl'

print '%s is %d is' %(username,age)

3:字典

字典是:key--value结构的存储方式

 

#定义字典

people={ 'username':'zl',

          'password':'zlzl'

}

#获取字典的内容

print "%s is" %people['username']

 

 

4:序列

#定义一个序列

people=['zl','maer','tgc','cdu']

#遍历第二个元素结束的前三个元素

print people[1:3]

注:数据结构是程序设计里面很是重要的部分,编程用的最频繁的部分。更多python内容,将陆续更新!

相关文章
相关标签/搜索