Home  >  Article  >  Backend Development  >  What does def mean in python

What does def mean in python

(*-*)浩
(*-*)浩Original
2019-06-24 13:23:4457243browse

Functions are similar to encapsulated program fragments. Allows you to give a block of statements a name, allowing you to run it any number of times using the specified name anywhere in your program.

What does def mean in python

def (the first three letters of define) is a keyword used to declare a function. (Recommended learning: Python video tutorial)

The format of def declaration function is:

def 函数名(参数1,参数2,...,参数n):
     函数体

For example:

def fib(n):                   
   print 'n =', n            
   if n > 1:                 
       return n * fib(n - 1)    
   else:                     
       print 'end of the line'        
   return 1

The function return value type is not fixed, and there is no need to specify the data type of its return value when declaring a function.

The function can even have no return value. If there is no return value, the system will return the empty value None by default.

Optional parameters: You can specify the default value of the parameter. If no parameter is specified when calling, the default value will be used.

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What does def mean in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn