元祖:sxs = (“cc”,"dcd") 不可更改 调用:sxs[0],sxs[1]
列表:sax = [ "sx", "sx"] 可更改 调用 :sax[0],sax[1]
更改: sax[count] = "sdcs"
添加一个元素:sax.append("dscs")
添加多个元素:sax.extend([ "sc", "cds"])
temperatures = [12, 11,32,32]
temperatures.append(34)
temperatures.extend([21,232,432])
查看:temperatures
从列表中创建的片段是列表,丛原组中创建的片段还是元祖,字符串的片段还是字符串
python 核心类型: 元组,列表,字典,集合
三种特殊类型:None True False
关于 ‘_doc_' 的 ’AttributeError‘
代码如下:
# Filename:
doc.py
def printMax(x, y):
'''Prints the maximum of two numbers.
The two values must be integers.'''
x = int(x)
y = int(y)
if x > y:
print x, 'is maximum'
else:
print y, 'is maximum'
printMax(3, 5)
print printMax.__doc__
运行结果:
xiyousmalltiger@xiyousmalltiger-laptop:~$ python doc.py
5
Traceback (most recent call last):
File "doc.py", line 14, in <module>
print printMax._doc_
AttributeError: 'function' object has no attribute '_doc_'
请问是什么原因?是不是我系统里的python安装的不完整?我的系统为Ubuntu8.10
================
================
# Filename:
def printMax(x, y):
printMax(3, 5)
print printMax.__doc__
运行结果:
xiyousmalltiger@xiyousmalltiger-laptop:~$ python doc.py
5
Traceback (most recent call last):
AttributeError: 'function' object has no attribute '_doc_'
请问是什么原因?是不是我系统里的python安装的不完整?我的系统为Ubuntu8.10
================
================
回复 1# smalltiger.lee 的帖子
是__doc__属性,而不是_doc_属性,注意是两个下划线。