Python笔记一
来源:互联网 发布:淘宝美式家具品牌 编辑:程序博客网 时间:2024/06/05 07:50
(1)builtin_function_or_method' object has no attribute '__getitem__
elements = []
# then use the range function to do 0 to 5 counts
for i in range(0, 6) :
print "Adding %d to the list : " % i
# append is a function that lists understand
elements.append[i]
for i in elements :
print "Element was: %d " % i
【报错】
Traceback (most recent call last):
File "ex32.py", line 29, in <module>
elements.append[i]
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
【修改】
elements.append[i] ===》 elements.append(i)
(2)函数注解
extest.py
def cthulhu_room() :
""" This is cthulhu_room function"""
使用方法:
[Harvey@/Users/Harvey/mystuff]cat extest.py
def cthulhu_room() :
""" This is cthulhu_room function"""
[Harvey@/Users/Harvey/mystuff]python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import extest
>>> help(extest)
>>> help(extest.cthulhu_room)
(3)dict的 items(), keys(), values()
Python的字典的items(), keys(), values()都返回一个list
[python] view plaincopy
>>> dict = { 1 : 2, 'a' : 'b', 'hello' : 'world' }
>>> dict.values()
['b', 2, 'world']
>>> dict.keys()
['a', 1, 'hello']
>>> dict.items()
[('a', 'b'), (1, 2), ('hello', 'world')]
>>>
0 0
- Python学习笔记(一)
- Python学习笔记[一]
- Python学习笔记一
- python学习笔记(一)
- Python学习笔记(一)
- Python学习笔记一
- python学习笔记一
- python 学习笔记一
- python 多线程笔记一
- python 学习笔记一
- python 笔记(一)
- python笔记(一)
- python学习笔记: 一
- python学习笔记(一)
- Python学习笔记(一)
- python基础笔记(一)
- python学习笔记一
- python学习笔记一
- 源代码解读Cas实现单点登出(single sign out)功能实现原理
- 堆排序 - 不稳定的排序
- 织梦 channel 标签 指定typeid时 currentstyle无效的修复办法
- 神奇的table-cell
- Marlin固件之—:基础入门与测试
- Python笔记一
- 二进制中1的个数
- DOM——JavaScript高级程序设计笔记(8)
- c++ 之typedef
- MyEclipse使用总结——MyEclipse10安装SVN插件
- buffer busy waits
- 抽象类的相关问题
- ViewStub的学习,展开部常用的控件
- sdnu 1078 食物链(并查集)