Beginning PythonFrom Novice to Professional, Second Edition 2008 phần 3

Trong chương này, bạn đã nhìn thấy một số loại báo cáo: In ấn: Bạn có thể sử dụng câu lệnh in để in một vài giá trị bằng cách tách chúng bằng dấu phẩy. Nếu bạn kết thúc câu bằng dấu phẩy, sau đó báo cáo in ấn sẽ tiếp tục in trên cùng một dòng. | CHAPTER 5 CONDITIONALS LOOPS AND SOME OTHER STATEMENTS 111 PRIMING THE SCOPE When supplying a namespace for exec or eval you can also put some values in before actually using the namespace scope scope x 2 scope y 3 eval x y scope 6 In the same way a scope from one exec or eval call can be used again in another one scope exec x 2 in scope eval x x scope 4 Actually exec and eval are not used all that often but they can be nice tools to keep in your back pocket figuratively of course . A Quick Summary In this chapter you ve seen several kinds of statements Printing You can use the print statement to print several values by separating them with commas. If you end the statement with a comma later print statements will continue printing on the same line. Importing Sometimes you don t like the name of a function you want to import perhaps you ve already used the name for something else. You can use the import .as. statement to locally rename a function. Assignments You ve seen that through the wonder of sequence unpacking and chained assignments you can assign values to several variables at once and that with augmented assignments you can change a variable in place. Blocks Blocks are used as a means of grouping statements through indentation. They are used in conditionals and loops and as you see later in the book in function and class definitions among other things. Conditionals A conditional statement either executes a block or not depending on a condition Boolean expression . Several conditionals can be strung together with if elif else. A variation on this theme is the conditional expression a if b else c. Assertions An assertion simply asserts that something a Boolean expression is true optionally with a string explaining why it must be so. If the expression happens to be false the assertion brings your program to a halt or actually raises an exception more on that 112 CHAPTER 5 CONDITIONALS LOOPS AND SOME OTHER STATEMENTS in Chapter 8 . It s better to find an error

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.