python 之 看yield的傳回值

含有yield的函數就是產生器,不是普通的函數。產生器包含有迭代器,“雨果”不明白什麼是產生器和迭代器參見http://blog.csdn.net/xiaofeng_yan/archive/2010/09/27/5910215.aspx下面重點說一下,怎麼看 yield 的傳回值。大家要記住,看yield的值必須在迴圈裡,因為只有在迴圈裡才能使yield傳回值或者具有可迭代的函數裡如列表。比如:def test(lst):        try:                for

Python的partition字串函數

轉載:http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246121c35b8fd7c714c428896207a52ef0f07bbae616f615466e4c096c957d9bb92282b8d27203541c6171d9152e9911b79d620e118baef5fbcfcab6fcf&p=882a9643d58512a05beace375744cf2

關於Python中以字母r/R,或字母u/U 開頭的字串

轉載:http://www.crifan.com/python_string_with_leading_char_r_u/(1)以r或R開頭的python中的字串表示(非轉義的)原始字串python裡面的字元,如果開頭處有個r,比如:(r’^time/plus/\d{1,2}/$’,

Python調試利器PDB

結束添加print然後執行指令碼的低效Debug方式,熟悉GDB的同學應該很容易就接受PDB。官方文檔地址:http://docs.python.org/library/pdb.html。使用PDB的方式有兩種,其中一種是在指令碼中添加代碼,不覺得這種方式比print好在哪裡,所以這種方式此文不表。這裡我們只學習PDB的命令列使用方式。    1)進入命令列Debug模式,python -m pdb myscript.py    2)h:(help)協助    3)w:(where)列印當前執行

Python核心編程之Regex-練習題解答

1. 識別下列字串:“bat,” “bit,” “but,” “hat,” “hit,” 或 “hut”  import redata=r'but,'patt='b.t,?'m=re.search(patt, data)if m is not None: print m.group()  2.匹配用一個空格分隔的任意一對單詞,比如,名和姓     patt='/S+/s/S+'  3. 匹配用一個逗號和一個空格分開的一個單詞和一個字母。例如,英文人名中的姓和名 的首字母     

python核心編程第八章習題答案(1)

8-9  Fibonacci 數列. Fibonacci 數列形如 1, 1, 2, 3, 5, 8, 13, 21, 等 等. 也就是說, 下一個值是序列中前兩個值之和. 寫一個函數, 給定 N , 返回第 N 個 Fibonacci 數字#Filename:test8-9.pydef Fibonacci(N): if N<=0: return -1 elif N<=2: return 1 else: return

Working with Excel Files in Python

轉: http://www.python-excel.org/Working with Excel Files in PythonThis site contains pointers to the best information available about working withExcel files in thePython programming language.The PackagesThere are python packages available to work

用python來嗅探QQ號碼

QQ使用udp協議來和伺服器進行通訊,當資料包在傳輸的時候。udp報文被抓了下來。而登陸包是以0x02開頭0x03為結尾的,我們先判斷是否為正確的登陸包,當然,登陸包的長度都為102個位元組。我們取出結構中特定的位置,就是你的QQ號碼了# -*- coding: cp936 -*-import pcap ,structpack=pcap.pcap() pack.setfilter('udp')key=''for recv_time,recv_data in pack:  

用Python指令碼語言建立一個基於應用程式的GUI快速啟動

用Python指令碼語言建立一個基於應用程式的GUI快速啟動開發人員線上 Builder.com.cn 更新時間:2007-02-27 作者:builder.com.cn

Use python win32gui for drawing

 import win32guifrom re import matchdef draw_line(): print 'x1,y1,x2,y2?' s=raw_input() if match('/d+,/d+,/d+,/d+',s): x1,y1,x2,y2=s.split(',') x1=int(x1) y1=int(y1) x2=int(x2) y2=int(y2)

python列印變數的標識符、類型和值

# Fig. 2.13: fig02_13.py# Displaying an object's location, type and value.# prompt the user for inputinteger1 = raw_input( "Enter first integer:/n" ) # read a stringprint "integer1: ", id( integer1 ), type( integer1 ),

scite python API

'''gen_python_api.py generates a python.api file for SciTEThe generated api file includes *) all Python keywords *) all builtin functions *) all module attributesModule functions are represented by their docstring if available,otherwise by the

Python tkinter 包含的外掛程式類型 & tkinter中可變的變數

tkinter是安裝python就內建的一個GUI庫,跨平台,雖然簡單,我看見網上很多人說學這個GUI庫沒意思,現在那麼多好的GUI庫,不過我認為存在即合理,總有學習的理由。想借這個GUI庫學學簡單的GUI介面設計和python關於物件導向編程的知識。tkinter包含了一些小外掛程式,如下所述:外掛程式與說明Button 可點擊的按鈕Canvas 用於繪製或顯示映像映像的地區Checkbutton 可點擊的框,其狀態可以是選定的或未選定的Entry 可供使用者輸入資料的單行文字框Frame

Cocos2d-python 介紹

cocos2d is a framework for building 2D games, demos, and other graphical/interactive applications.cocos2d simplifies the game development in these areas:Flow control: Manage the flow control between different scenes in an easy waySprites: Fast and

python time,datetime,string轉換

#把datetime轉成字串 def datetime_toString(dt): return dt.strftime("%Y-%m-%d-%H") #把字串轉成datetime def string_toDatetime(string): return datetime.strptime(string, "%Y-%m-%d-%H") #把字串轉成時間戳記形式 def string_toTimestamp(strTime): return

Python發送Email

Python對於Email的分成兩個部分:對於POP、SMTP的支援。對於Email資料的支援。第一部分: 用POP、SMTP來讀取信件:import getpass, poplibM = poplib.POP3('localhost')M.user(getpass.getuser())M.pass_(getpass.getpass())numMessages = len(M.list()[1])for i in range(numMessages): for j in M.retr(i+

python Python 解析xml檔案出現錯誤xml.parsers.expat.ExpatError: unknown encoding 的解決

python 解析xml檔案出現錯誤:xml.parsers.expat.ExpatError: unknown encoding: line 1, column 30這是由於編碼問題。原因說明:shell環境的 LANG=zh_CN.UTF-8執行一個程式,產生了一個XML檔案,在程式中將xml檔案的編碼設定成了GB2312,如“<?xml version="1.0"

python 3中對list進行sort時,傳回值為None

進行在用python的list結構時, 發現一個問題:methods = ['blogger.deletePost', 'blogger.getUsersBlogs', 'metaWeblog.editPost', 'metaWeblog.getCategories', 'metaWeblog.getPost', 'metaWeblog.getRecentPosts', 'metaWeblog.newMediaObject', 'metaWeblog.newPost',

Python Effective Programming

文章目錄 HTML Tags and JavaScript tutorial  HTML Tags and JavaScript tutorialPython Effective ProgrammingThese are some experiences of effective python programming that shown in a slide

python 3.2 IDLE入門

IDLE是Python軟體包內建的一個整合式開發環境,初學者可以利用它方便地建立、運行、測試和調試Python程式。一、IDLE的安裝實際上,IDLE是跟Python一起安裝的,不過要確保安裝時選中了“Tcl/Tk”組件,準確地說,應該是不要取消該組件,因為預設時該組件是處於選中狀態的。二、IDLE的啟動安裝Python後,我們可以從“開始”菜單→“所有程式”→“Python 2.7”→“IDLE(Python

總頁數: 2974 1 .... 215 216 217 218 219 .... 2974 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.