程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Please answer the basic questions about Python!

編輯:Python

self-taught python in , Self study books are part of the Turing community 《 Programming x The first white book python Introductory book 》
When it comes to defining functions ,
Have said

ad locum , It is mentioned in the book that the statement after the function colon will automatically become a statement block (block)
there block It means that the statement is automatically indented after the function , Whole block Are all the statements in it functions ?




Take the answer :

Yes . Carriage return after colon will automatically indent one space , As long as the input code is within the method , It belongs to the code block in the current method .
It can be understood as , The code on the right after the current method ( Non peer ) All belong to the current method .
A code block is a set of functions made up of code “ unit ”. A block of code can run alone . Like a function (function) Or a class (class) Definition 、 A module (module) All code blocks , for example :

def print_parity(x):    if x % 2 == 0:        print(x, "is even")    else:        print(x, "is odd")

This is a function definition (function definition), This function can be used to query the parity of an input number . This function is just a code block , Can operate independently .



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved