mirror of
https://github.com/beyondx/Notes.git
synced 2026-02-03 18:33:26 +08:00
add lots file of APUE
This commit is contained in:
40
Zim/Programme/python/python笔记/dict.txt
Normal file
40
Zim/Programme/python/python笔记/dict.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:21:05+08:00
|
||||
|
||||
====== dict ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
Help on class dict in module __builtin__:
|
||||
|
||||
class dict(object)
|
||||
| dict() -> new empty dictionary
|
||||
| dict(mapping) -> new dictionary initialized from **a mapping object**'s #mapping为__一个__pairs对象
|
||||
| (key, value) pairs
|
||||
| dict(iterable) -> new dictionary initialized as if via:
|
||||
| d = {}
|
||||
| for **k, v** in iterable: #迭代器对象每次返回的元素必须是一个容器类型,__容器中元素的个数为2__.**如[a,b], "ab",(a,b)**
|
||||
| d[k] = v
|
||||
| dict(__**kwargs)__ -> new dictionary initialized with the name=value pairs
|
||||
| in the keyword argument list. For example: dict(one=1, two=2)
|
||||
|
|
||||
| Methods defined here:
|
||||
|
||||
|
||||
>>> dict(__[('sape', 4139), ('guido', 4127), ('jack', 4098)]__)
|
||||
{'sape': 4139, 'jack': 4098, 'guido': 4127}
|
||||
|
||||
>>> dict([(x, x**2) for x in (2, 4, 6)]) # use a list comprehension
|
||||
{2: 4, 4: 16, 6: 36}
|
||||
|
||||
>>> dict(sape=4139, guido=4127, jack=4098)
|
||||
{'sape': 4139, 'jack': 4098, 'guido': 4127}
|
||||
tel = {'jack': 4098, 'sape': 4139}
|
||||
|
||||
>>> dc=dict(["df","12"]);dc #["df","12"]为一科迭代对象,每次返回的元素为两个字符的str,所以可以被unpack给key,value
|
||||
{'1': '2', 'd': 'f'}
|
||||
>>> dc=dict(["df",__"123"__]);dc
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: dictionary update sequence element __#1 has length 3; 2 is required__
|
||||
>>>
|
||||
20
Zim/Programme/python/python笔记/float.txt
Normal file
20
Zim/Programme/python/python笔记/float.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:20:56+08:00
|
||||
|
||||
====== float ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
>>> float("0xff")
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: invalid literal for float(): 0xff
|
||||
>>>
|
||||
|
||||
>>> __float.fromhex("0xfff")__
|
||||
4095.0
|
||||
>>>
|
||||
|
||||
>>> float("0.111")
|
||||
0.111
|
||||
>>>
|
||||
37
Zim/Programme/python/python笔记/int_long.txt
Normal file
37
Zim/Programme/python/python笔记/int_long.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:20:52+08:00
|
||||
|
||||
====== int long ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
>>> 1&2 #按__位与__
|
||||
0
|
||||
|
||||
>>> 0xff&0xf1 #按位与
|
||||
241
|
||||
>>> 0xff&0xf0
|
||||
240
|
||||
>>> __hex__(0xff&0xf0) #返回的__字符串__
|
||||
'0xf0'
|
||||
__与hex()类似, bin(), oct()等返回的都是int或long型的字符串代表__
|
||||
|
||||
>>> 1&&2 __#python没有&&, ||, !逻辑运算符,但是有and, or, not,而且这三个逻辑运算符返回的是最后一个元素的内容__
|
||||
File "<stdin>", line 1
|
||||
1&&2
|
||||
^
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
>>> 1 and 2 __#返回的是最后一个元素的内容而不是True或False,这里为2__
|
||||
2
|
||||
|
||||
>>> 'fff' & 'dfad' __#str类型没有定义__and__方法,所以没有位运算__
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: unsupported operand type(s) for &: 'str' and 'str'
|
||||
>>> help(str)
|
||||
|
||||
>>> 'fff' and 'dfad'
|
||||
'dfad'
|
||||
>>>
|
||||
|
||||
25
Zim/Programme/python/python笔记/list.txt
Normal file
25
Zim/Programme/python/python笔记/list.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:21:01+08:00
|
||||
|
||||
====== list ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
>>> l=range(1,10)
|
||||
>>> l
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
>>> __l[1:8:-1]__
|
||||
[]
|
||||
>>> l[8:1:-1]
|
||||
[9, 8, 7, 6, 5, 4, 3]
|
||||
>>> __l[::-1]__
|
||||
[9, 8, 7, 6, 5, 4, 3, 2, 1]
|
||||
>>> l[-1::-1]
|
||||
[9, 8, 7, 6, 5, 4, 3, 2, 1]
|
||||
>>> __l[-1:-9:-1]__
|
||||
[9, 8, 7, 6, 5, 4, 3, 2]
|
||||
>>> l[:]
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
>>> l[::]
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
18
Zim/Programme/python/python笔记/set.txt
Normal file
18
Zim/Programme/python/python笔记/set.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:21:08+08:00
|
||||
|
||||
====== set ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
>>> set1=set(1,2,3)
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: set expected __at most 1 arguments,__ got 3
|
||||
|
||||
>>> set1=set((1,2,3))
|
||||
>>> set1
|
||||
set([1, 2, 3])
|
||||
>>>
|
||||
|
||||
|
||||
40
Zim/Programme/python/python笔记/str.txt
Normal file
40
Zim/Programme/python/python笔记/str.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:20:41+08:00
|
||||
|
||||
====== str ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
| join(...)
|
||||
| S.join(iterable) -> string
|
||||
|
|
||||
| Return a string which is the concatenation of __the strings in the__
|
||||
__ | iterable__. The separator between elements is S.
|
||||
|
||||
iterable迭代器对象每次返回的__必须是字符串对象__。
|
||||
|
||||
>>> ":".join("abcd")
|
||||
'a:b:c:d'
|
||||
|
||||
>>> ":".join(['a','b','c','d'])
|
||||
'a:b:c:d'
|
||||
|
||||
>>> ":".join(['a',__123__,'c'])
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: sequence item 1: __expected string__, int found
|
||||
|
||||
>>> ":".join(['a',['ab'],'c'])
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: sequence item 1: expected string, list found
|
||||
>>>
|
||||
|
||||
| rsplit(...)
|
||||
| S.rsplit([sep [,maxsplit]]) -> list of strings
|
||||
|
|
||||
| Return a list of the words in the string S, using sep as the
|
||||
| delimiter string, starting at the end of the string and working
|
||||
| to the front. If maxsplit is given, at most maxsplit splits are
|
||||
| done. If sep is not specified or is __None__, any whitespace string
|
||||
| is a separator.
|
||||
38
Zim/Programme/python/python笔记/unpack.txt
Normal file
38
Zim/Programme/python/python笔记/unpack.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:47:32+08:00
|
||||
|
||||
====== unpack ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
>>> for k,v in ["fdf",23,"dfdf",33]:
|
||||
... print k,v
|
||||
...
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: __too many__ values to unpack
|
||||
|
||||
顺序容器类型如str, list, tuple__每次迭代时只能返回其中的一个元素__。
|
||||
所以第一次返回循环返回**"fdf"**,但是它有三个元素最多只能赋值给两个
|
||||
变量。
|
||||
|
||||
>>> for k,v in "dfdf":
|
||||
... print k,v
|
||||
...
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: __need more than 1 value__ to unpack
|
||||
|
||||
字符串迭代时,每次返回其中的一个字符。所以最多只能unpack给一个变量。
|
||||
|
||||
>>> k,v="dfdf"
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: __too many values to unpack__
|
||||
|
||||
unpack一个顺序容器类型时,左边变量的数目必须要与容器中元素的个数相同。
|
||||
|
||||
>>> k,v="df"
|
||||
>>> print k,v
|
||||
d f
|
||||
>>>
|
||||
7
Zim/Programme/python/python笔记/内置函数.txt
Normal file
7
Zim/Programme/python/python笔记/内置函数.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Content-Type: text/x-zim-wiki
|
||||
Wiki-Format: zim 0.4
|
||||
Creation-Date: 2012-10-04T13:21:30+08:00
|
||||
|
||||
====== 内置函数 ======
|
||||
Created Thursday 04 October 2012
|
||||
|
||||
Reference in New Issue
Block a user