tailieunhanh - Beginning PythonFrom Novice to Professional, Second Edition 2008 phần 10

Để bây giờ, cho phép của chỉ giả định rằng _handle sẽ chăm sóc của các xử lý nội bộ của một truy vấn kiểm tra cho dù tập tin tồn tại này Node cụ thể, lấy dữ liệu, và vv và rằng nó trả về một mã và một số dữ liệu, chỉ là truy vấn bản thân là nghĩa vụ phải. | APPENDIX B PYTHON REFERENCE 593 The for Statement The for statement is used for repeated execution looping over the elements of sequences or other iterable objects objects having an_iter_method that returns an iterator . It may include an else clause which is executed if the loop finishes normally without any break or return statements for instance . Example for i in range 10 0 -1 print i print Ignition The try Statement The try statement is used to enclose pieces of code where one or more known exceptions may occur and enables your program to trap these exceptions and perform exception-handling code if an exception is trapped. The try statement can combine several except clauses handling exceptional circumstances and finally clauses executed no matter what useful for cleanup . Example try 1 0 except ZeroDivisionError print Can t divide anything by zero. finally print Done trying to calculate 1 0 The with Statement The with statement is used to wrap a block of code using a so-called context manager allowing the context manager to perform some setup and cleanup actions. For example files can be used as context managers and they will close themselves as part of the cleanup. Note In Python you need from__future import with_statement for the with statement to work as described. Example with open as myfile dosomething myfile The file will have been closed here 594 APPENDIX B PYTHON REFERENCE Function Definitions Function definitions are used to create function objects and to bind global or local variables to these function objects. Example def double x return x 2 Class Definitions Class definitions are used to create class objects and to bind global or local variables to these class objects. Example class Doubler def init__ self value value def double self 2 APPENDIX C Online Resources ks you learn Python the Internet will serve as an invaluable resource. This appendix describes some of the web sites that may be of interest .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.