jack0he的个人博客分享 http://blog.sciencenet.cn/u/jack0he

博文

Python-Note-8-data structure-lists (continue)

已有 2388 次阅读 2017-4-12 04:58 |个人分类:Python 笔记|系统分类:科研笔记

Using for loops with lists


Example-1

animal=['cat','dog','fish','elephant']

for i in animal:

   print('The animal is '+i)

---

outPut

The animal is cat

The animal is dog

The animal is fish

The animal is elephant


Is a specific value in a list?

'cat' in animal

outPut

True


Multiple assignment trick

cat=['fat','orange','loud']

size=cat[0]

color=cat[1]

disposition=cat[2]


cat=['fat','orange','loud']

size,color,disposition=cat


a,b='alice','bob'  -->a='alice', b='bob'

a,b=b,a  -->c=a,a=b,b=c


For more, https://automatetheboringstuff.com/chapter4/, https://docs.python.org/3/tutorial/datastructures.html#more-on-lists, http://www.runoob.com/python/python-variable-types.html





https://wap.sciencenet.cn/blog-850613-1048321.html

上一篇:Python-note-7-data structure-lists
收藏 IP: 80.101.95.*| 热度|

1 张海权

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-19 16:16

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部