青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

任我行

一天一個腳印......
每日一句:
posts - 54, comments - 218, trackbacks - 1, articles - 0
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

Python學習(二)

Posted on 2005-10-11 17:00 任我行 閱讀(1541) 評論(0)  編輯 收藏 引用 所屬分類: Python

今天繼續dive into python.

12、列表與字符串
  1)用一個字符串對象的join 方法將列表元素連接成單個字符串,此字符串充當分隔符。
  2)join 只用用于字符串列表;它不進行任何的類型強制轉換。連接一個存在一個或多個非字符串元素的列表將引發一個異常。
  3)用一個字符串對象的split 方法將列表元素連接成單個字符串,此字符串充當分隔符。
  4)split 接受一個可選的第二個參數,它是要分割的次數。
  5)split 無參數調用時,默認為以空白為分隔符(空格/換行/制表符),多個連續空白初見為一個。

13、導入模塊
  1)Python用兩種方法導入模塊,一是import module,一種是from module import,
  2)第一種方法導入整個模塊,對其屬性或方法的引用要加限制名,如:
>>> import types
>>> types.FunctionType
  3)第二種方法將模塊的方法和屬性直接導入名字空間中,可以直接引用這些方法和屬性,如:
>>> from types import FunctionType
>>> FunctionType
  4)兩種方法各有利弊,前者可明確指定要導入的方法和屬性,并直接引用,比較方便;對于屬性或方法重名的情況,則后者非常有用。

14、函數的參數
  1)函數的參數可以擁有缺省值,某個參數有什么缺省值在定義函數時指明,
  2)擁有缺省值的參數為可選參數,否則為必備參數,即調用函數時必須為必備參數提供參數,如果沒有對可選參數提供參數值,則其使用缺省值。
  3)調用函數時,可以通過指定參數名而以任意次序來傳遞參數,稱為定名參數。如:
定義:
def help(object, spacing=10, collapse=1):
合法調用:
help(odbchelper)
help(odbchelper, 12)
help(odbchelper, collapse=0)
help(spacing=15, object=odbchelper)
  4)參數是個字典,缺省可以不指定名字而用順序將參數名與值匹配起來。

15、內置函數
  1)所有Python內置函數被組合進一個名叫 __builtins__ (前后有兩個下劃線)的特別模塊中。
  2)內置函數dir 返回任意一個對象的屬性和方法的列表。
  3)內置函數str 強制將任一種類型的數據轉化為字符串,對python的空值None,則str(None)返回字符串"None”.
  4)內置函數type 返回任意對象的數據類型。
  5)使用函數 getattr 得到對象的各種引用,這個過程中方法沒有被調用。
  6)使用getattr得到引用后,其返回值為方法,可以調用相應的函數。如下:
>>>getattr(li, "append")("Moe")
  
16
、列表映射過濾語法
[mapping-expression for element in source-list if filter-expression]

17and-or技巧,bool and a or b來說,
  1)邏輯運行采用了快捷方式,即如果or前值為真,是不再計算后面的值,并返回前面的結果
  2) (bool and [a] or )[0]的方法,可以實現與cbool?a:b的功能

18lambda函數
  1)可以使用lambda定義單行的最小函數,格式如下:
funcVar = lambda x : x...
  沒有名字,返回是默認的。上式中可以沒有funcVar,有funcVar時可與正常函數一樣調用,沒有funcVar時可如下調用:
(lambda x:x...)(a)
  2)lambda函數可以接受一到多個參數(包括可選參數),返回單個表達式的值,函數中不能包含命令,表達式不能超過一個。

19、一些小技巧
  1)python幾乎總是在操作列表
  2)字符串的ljust(spacing)可以在右邊加空格以達到spacing值所示的長度,當spacing的值小于字符串的長度時,不會截斷。


:builtin的屬性表

屬性

說明

ArithmeticError

Base class for arithmetic errors.

AssertionError

Assertion failed.

AttributeError

Attribute not found.

DeprecationWarning

Base class for warnings about deprecated features.

EOFError

Read beyond end of file.

EnvironmentError

Base class for I/O related errors.

Exception

Common base class for all exceptions.

FloatingPointError

Floating point operation failed.

FutureWarning

Base class for warnings about constructs that will change semantically in the future.

IOError

I/O operation failed.

ImportError

Import can't find module, or can't find name in module.

IndentationError

Improper indentation.

IndexError

Sequence index out of range.

KeyError

Mapping key not found.

KeyboardInterrupt

Program interrupted by user.

LookupError

Base class for lookup errors.

MemoryError

Out of memory.

NameError

Name not found globally.

NotImplementedError

Method or function hasn't been implemented yet.

OSError

OS system call failed.

OverflowError

Result too large to be represented.

OverflowWarning

Base class for warnings about numeric overflow.

PendingDeprecationWarning

Base class for warnings about features which will be deprecated in the future.

ReferenceError

Weak ref proxy used after referent went away.

RuntimeError

Unspecified run-time error.

RuntimeWarning

Base class for warnings about dubious runtime behavior.

StandardError

Base class for all standard Python exceptions.

StopIteration

Signal the end from iterator.next().

SyntaxError

Invalid syntax.

SyntaxWarning

Base class for warnings about dubious syntax.

SystemError

Internal error in the Python interpreter. Please report this to the Python maintainer, along with the traceback, the Python version, and the hardware/OS platform and version.

SystemExit

Request to exit from the interpreter.

TabError

Improper mixture of spaces and tabs.

TypeError

Inappropriate argument type.

UnboundLocalError

Local name referenced but not bound to a value.

UnicodeDecodeError

Unicode decoding error.

UnicodeEncodeError

Unicode encoding error.

UnicodeError

Unicode related error.

UnicodeTranslateError

Unicode translation error.

UserWarning

Base class for warnings generated by user code.

ValueError

Inappropriate argument value (of correct type).

Warning

Base class for warning categories.

WindowsError

MS-Windows OS system call failed.

ZeroDivisionError

Second argument to a division or modulo operation was zero.

builtin方法(函數)

方法

說明

__import__

__import__(name, globals, locals, fromlist) -> module Import a module. The globals are only used to determine the context; they are not modified. The locals are currently unused. The fromlist should be a list of names to emulate ``from name import ...'', or an empty list to emulate ``import name''. When importing a module from a package, note that __import__('A.B', ...) returns package A when fromlist is empty, but its submodule B when fromlist is not empty.

abs

abs(number) -> number Return the absolute value of the argument.

apply

apply(object[, args[, kwargs]]) -> value Call a callable object with positional arguments taken from the tuple args, and keyword arguments taken from the optional dictionary kwargs. Note that classes are callable, as are instances with a __call__() method. Deprecated since release 2.3. Instead, use the extended call syntax: function(*args, **keywords).

callable

callable(object) -> bool Return whether the object is callable (i.e., some kind of function). Note that classes are callable, as are instances with a __call__() method.

chr

chr(i) -> character Return a string of one character with ordinal i; 0 <= i < 256.

cmp

cmp(x, y) -> integer Return negative if x<y, zero if x==y, positive if x>y.

coerce

coerce(x, y) -> None or (x1, y1) When x and y can be coerced to values of the same type, return a tuple containing the coerced values. When they can't be coerced, return None.

compile

compile(source, filename, mode[, flags[, dont_inherit]]) -> code object Compile the source string (a Python module, statement or expression) into a code object that can be executed by the exec statement or eval(). The filename will be used for run-time error messages. The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. The dont_inherit argument, if non-zero, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or zero these statements do influence the compilation, in addition to any features explicitly specified.

delattr

delattr(object, name) Delete a named attribute on an object; delattr(x, 'y') is equivalent to ``del x.y''.

dir

dir([object]) -> list of strings Return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it: No argument: the names in the current scope. Module object: the module attributes. Type or class object: its attributes, and recursively the attributes of its bases. Otherwise: its attributes, its class's attributes, and recursively the attributes of its class's base classes.

divmod

divmod(x, y) -> (div, mod) Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.

eval

eval(source[, globals[, locals]]) -> value Evaluate the source in the context of globals and locals. The source may be a string representing a Python expression or a code object as returned by compile(). The globals and locals are dictionaries, defaulting to the current globals and locals. If only globals is given, locals defaults to it.

execfile

execfile(filename[, globals[, locals]]) Read and execute a Python script from a file. The globals and locals are dictionaries, defaulting to the current globals and locals. If only globals is given, locals defaults to it.

filter

filter(function or None, sequence) -> list, tuple, or string Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list.

getattr

getattr(object, name[, default]) -> value Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y. When a default argument is given, it is returned when the attribute doesn't exist; without it, an exception is raised in that case.

globals

globals() -> dictionary Return the dictionary containing the current scope's global variables.

hasattr

hasattr(object, name) -> bool Return whether the object has an attribute with the given name. (This is done by calling getattr(object, name) and catching exceptions.)

hash

hash(object) -> integer Return a hash value for the object. Two objects with the same value have the same hash value. The reverse is not necessarily true, but likely.

hex

hex(number) -> string Return the hexadecimal representation of an integer or long integer.

id

id(object) -> integer Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (Hint: it's the object's memory address.)

input

input([prompt]) -> value Equivalent to eval(raw_input(prompt)).

intern

intern(string) -> string ``Intern'' the given string. This enters the string in the (global) table of interned strings whose purpose is to speed up dictionary lookups. Return the string itself or the previously interned string object with the same value.

isinstance

isinstance(object, class-or-type-or-tuple) -> bool Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object's type. The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for isinstance(x, A) or isinstance(x, B) or ... (etc.).

issubclass

issubclass(C, B) -> bool Return whether class C is a subclass (i.e., a derived class) of class B. When using a tuple as the second argument issubclass(X, (A, B, ...)), is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.).

iter

iter(collection) -> iterator iter(callable, sentinel) -> iterator Get an iterator from an object. In the first form, the argument must supply its own iterator, or be a sequence. In the second form, the callable is called until it returns the sentinel.

len

len(object) -> integer Return the number of items of a sequence or mapping.

locals

locals() -> dictionary Update and return a dictionary containing the current scope's local variables.

map

map(function, sequence[, sequence, ...]) -> list Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence).

max

max(sequence) -> value max(a, b, c, ...) -> value With a single sequence argument, return its largest item. With two or more arguments, return the largest argument.

min

min(sequence) -> value min(a, b, c, ...) -> value With a single sequence argument, return its smallest item. With two or more arguments, return the smallest argument.

oct

oct(number) -> string Return the octal representation of an integer or long integer.

ord

ord(c) -> integer Return the integer ordinal of a one-character string.

pow

pow(x, y[, z]) -> number With two arguments, equivalent to x**y. With three arguments, equivalent to (x**y) % z, but may be more efficient (e.g. for longs).

range

range([start,] stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0. When step is given, it specifies the increment (or decrement). For example, range(4) returns [0, 1, 2, 3]. The end point is omitted! These are exactly the valid indices for a list of 4 elements.

raw_input

raw_input([prompt]) -> string Read a string from standard input. The trailing newline is stripped. If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError. On Unix, GNU readline is used if enabled. The prompt string, if given, is printed without a trailing newline before reading.

reduce

reduce(function, sequence[, initial]) -> value Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty.

reload

reload(module) -> module Reload the module. The module must have been successfully imported before.

repr

repr(object) -> string Return the canonical string representation of the object. For most object types, eval(repr(object)) == object.

round

round(number[, ndigits]) -> floating point number Round a number to a given precision in decimal digits (default 0 digits). This always returns a floating point number. Precision may be negative.

setattr

setattr(object, name, value) Set a named attribute on an object; setattr(x, 'y', v) is equivalent to ``x.y = v''.

sum

sum(sequence, start=0) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start'. When the sequence is empty, returns start.

unichr

unichr(i) -> Unicode character Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

vars

vars([object]) -> dictionary Without arguments, equivalent to locals(). With an argument, equivalent to object.__dict__.

zip

zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)] Return a list of tuples, where each tuple contains the i-th element from each of the argument sequences. The returned list is truncated in length to the length of the shortest argument sequence.

 

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一区在线视频观看| 欧美11—12娇小xxxx| 国产亚洲一区二区三区在线观看 | 亚洲影视中文字幕| 亚洲最黄网站| 亚洲一区二区三区在线播放| 亚洲在线成人精品| 欧美自拍偷拍午夜视频| 久久久亚洲午夜电影| 老牛嫩草一区二区三区日本 | 中文在线资源观看网站视频免费不卡 | 久久精品五月婷婷| 亚洲男女毛片无遮挡| 亚洲视频久久| 午夜精品一区二区三区在线视| 91久久久在线| 99国产精品久久久久老师| 99精品免费| 香蕉成人久久| 欧美成人高清视频| 亚洲午夜激情| 久久综合中文| 欧美日韩一区不卡| 国产无遮挡一区二区三区毛片日本| 国产毛片一区二区| 亚洲国产精品一区二区第一页| 亚洲精品资源| 欧美一站二站| 亚洲精品免费在线观看| 中文久久乱码一区二区| 久久亚洲精品网站| 欧美三级电影大全| 亚洲国产精品一区二区第四页av| 99www免费人成精品| 欧美在线观看网址综合| 亚洲激情欧美激情| 欧美在线一区二区| 欧美视频二区| 亚洲激情专区| 久久亚洲精品中文字幕冲田杏梨| 亚洲国产欧美一区二区三区久久 | 亚洲婷婷免费| 欧美激情精品久久久| 亚洲欧美激情一区| 欧美日韩国产麻豆| 亚洲国产裸拍裸体视频在线观看乱了| 在线观看亚洲视频啊啊啊啊| 亚洲综合三区| 亚洲经典三级| 免费美女久久99| 激情成人亚洲| 久久久午夜视频| 亚洲欧美国产不卡| 欧美日韩一区二区在线观看| 在线观看中文字幕亚洲| 久久久美女艺术照精彩视频福利播放| 欧美国产综合| 老司机免费视频一区二区| 国产精品美女久久久久av超清| 亚洲国产精品久久精品怡红院| 午夜精品久久久久久久99热浪潮| 亚洲国产欧美国产综合一区| 久久久久久久综合色一本| 欧美久久久久中文字幕| 精品96久久久久久中文字幕无| 一本久久综合亚洲鲁鲁| 欧美jizz19性欧美| 久久久久久日产精品| 精品成人免费| 久久躁日日躁aaaaxxxx| 久久精品国产亚洲精品| 精品999网站| 牛牛影视久久网| 免费一级欧美在线大片| 亚洲精品日韩欧美| 亚洲三级影院| 国产精品你懂的在线欣赏| 欧美亚洲在线观看| 久久xxxx| 91久久精品日日躁夜夜躁欧美| 久久久久久亚洲精品中文字幕| 亚洲综合好骚| 在线观看欧美一区| 亚洲精品乱码久久久久久久久| 欧美国产丝袜视频| 亚洲性感美女99在线| 亚洲伊人伊色伊影伊综合网| 国产在线视频欧美| 亚洲国产aⅴ天堂久久| 欧美日韩三区| 久久久久**毛片大全| 麻豆9191精品国产| 亚洲在线不卡| 老牛嫩草一区二区三区日本| 一本色道久久88亚洲综合88| 亚洲欧美成人| 99ri日韩精品视频| 欧美一区综合| 亚洲日本成人| 午夜精品美女自拍福到在线| 伊人精品视频| 最新日韩在线| 国内精品伊人久久久久av影院| 免费在线日韩av| 欧美色欧美亚洲另类二区| 久久久夜色精品亚洲| 欧美欧美天天天天操| 久久裸体艺术| 欧美视频一区二区三区| 能在线观看的日韩av| 国产精品美女xx| 亚洲精品少妇网址| 亚洲电影下载| 欧美一区二区高清在线观看| 亚洲视频一区在线观看| 久久综合九色99| 久久久久久9| 国产精品久久久免费| 亚洲激情一区二区三区| 一区一区视频| 欧美在线观看www| 香港久久久电影| 欧美日韩国产二区| 欧美国产日韩一区| 伊人春色精品| 一区二区久久| 亚洲精品日韩在线观看| 一区视频在线看| 性欧美暴力猛交另类hd| 亚洲一卡久久| 欧美日韩高清一区| 亚洲黄网站在线观看| 亚洲国产99精品国自产| 久久成人国产精品| 欧美一区成人| 国产欧美日韩亚洲| 一区二区三区视频在线观看| 午夜精品影院| 国产毛片精品视频| 欧美在线免费一级片| 欧美日韩性生活视频| 欧美激情欧美激情在线五月| 黑人巨大精品欧美黑白配亚洲| 91久久精品视频| 亚洲人成在线观看| 欧美 日韩 国产一区二区在线视频 | 性欧美1819sex性高清| 欧美激情aⅴ一区二区三区| 欧美xxx成人| 在线观看欧美黄色| 美国十次成人| 欧美国产精品人人做人人爱| 亚洲第一精品久久忘忧草社区| 欧美一区二区在线视频| 久久深夜福利| 亚洲国产精品高清久久久| 欧美成年人视频网站| 亚洲欧洲三级电影| 亚洲视屏在线播放| 国产区在线观看成人精品| 欧美在线日韩精品| 欧美激情第五页| 亚洲一级在线观看| 黑人一区二区三区四区五区| 久久亚洲国产成人| 亚洲精品中文字| 欧美怡红院视频一区二区三区| 国产精品中文字幕欧美| 久久精品在线观看| 亚洲精选国产| 久久久久久69| 一区二区欧美日韩| 国产女人18毛片水18精品| 久久婷婷一区| 日韩一级精品视频在线观看| 午夜在线电影亚洲一区| 在线观看视频免费一区二区三区| 久久色中文字幕| 99精品视频一区| 免播放器亚洲| 香蕉av福利精品导航| 亚洲电影中文字幕| 国产精品久久国产愉拍| 久久婷婷综合激情| 亚洲欧美日韩综合aⅴ视频| 亚洲高清三级视频| 久久久久久久成人| 亚洲午夜精品久久久久久浪潮| 欧美日韩久久精品| 小辣椒精品导航| 91久久精品日日躁夜夜躁欧美 | 国产在线精品一区二区夜色| 欧美精品免费在线观看| 午夜视频在线观看一区二区三区| 裸体一区二区| 欧美在线视屏| 亚洲一区在线观看视频| 亚洲理论在线观看| 亚洲黄色精品| 尤物精品在线|