返戻値(return文)

返戻値を伴う関数定義

edit

   1 def double( x ):
   2     return( x * 2 )
   3 
   4 print( double( 12 ) )

   1 def add( x, y):
   2     return( x + y )
   3 
   4 print( add( 12, 23 ) )

複数の値を返す関数

edit

   1 import datetime
   2 
   3 def today_now():
   4     now = datetime.datetime.today()
   5     return( ((now.year, now.month, now.day), (now.hour,now.minute,now.second)) )
   6 
   7 (date, time) = today_now()
   8 print( date )
   9 print( time )

SoftEng: Python/Lang/Function/Return/Contents (last edited 2018-10-01 01:32:34 by TadashiIijima)