Changkun's Blog欧长坤的博客

Science and art, life in between.科学与艺术,生活在其间。

  • Home首页
  • Ideas想法
  • Posts文章
  • Tags标签
  • Bio关于
  • TOC目录
  • Overview概览
Changkun Ou

Changkun Ou

Human-AI interaction researcher, engineer, and writer.人机交互研究者、工程师、写作者。

Bridging HCI, AI, and systems programming. Building intelligent human-in-the-loop optimization systems. Informed by psychology, sociology, cognitive science, and philosophy.连接人机交互、AI 与系统编程。构建智能的人在环优化系统。融合心理学、社会学、认知科学与哲学。

Science and art, life in between.科学与艺术,生活在其间。

276 Blogs博客
165 Tags标签
  • List
  • Dicthinaries
  • Set
  • if
  • for
  • list comprehensions
Changkun's Blog欧长坤的博客

Python QuickStart

Published at发布于:: 2014-03-27   |   Reading阅读:: 1 min   |   PV/UV: /

Python Version: 2.7 We use python for rapid development. Mainly using the matrix operations, so we quickly introduce python collection type and control structure.

List

1
2
3
4
>>> wow=[]
>>> wow.append(1)
>>> wow.append('nice hat')
>>> wow

python has arryay data type, which similar to c/cpp/java/…, can contain only one type of data. This array type is faster than list when you are looping.

Dicthinaries

1
2
3
4
>>> wow={}
>>> wow['name']='euryugasaki'
>>> wow[123]=456
>>> wow

Set

1
2
3
4
5
6
7
8
>>> Set1 = [1,2,3,4,5,6,7,8,9]
>>> pSet1 = set(Set1)
>>> pSet1
>>> pSet2 = set([4,5,6,7])
>>> pSet2
>>> pSet1-pSet2
>>> pSet1|pSet2
>>> pSet1&pSet2

if

1
2
3
4
5
>>> val=10
>>> if val<9: print "hehe"
>>> if val<9:
...    print "hehe"
...

for

In for,while,or if statements, we use indentation to tell python which line of code belong inside these loops.

1
2
3
4
>>> pset=set([1,2,3,4,5])
>>> for item in pset:
...    print item
...

You can also loop over a dictionary, The item iterated over are acturally the dictionary keys.

list comprehensions

1
2
3
>>> wow = [1,2,3,4,5,6,7,8,9]
>>> newWOW = [item*3 for item in array if item>5]
>>> newWOW
#Python#
  • Author:作者: Changkun Ou
  • Link:链接: https://changkun.de/blog/posts/python-quickstart/
  • All articles in this blog are licensed under本博客所有文章均采用 CC BY-NC-ND 4.0 unless stating additionally.许可协议,除非另有声明。
论文都是逼出来的
谈谈对编程语言的一般性认识

Have thoughts on this?有想法?

I'd love to hear from you — questions, corrections, disagreements, or anything else.欢迎来信交流——问题、勘误、不同看法,或任何想说的。

hi@changkun.de
© 2008 - 2026 Changkun Ou. All rights reserved.保留所有权利。 | PV/UV: /
0%