Python関数
Pythonは、私たちが毎日話すように強力なプログラミング言語と言語で簡単です.Pythonプログラミング言語では、ソフトウェアやIT分野に存在するあらゆるタスクやアプリケーションを行うことができます.
文法
関数を定義する簡単な構文です.
パラメータは、その値を使用していくつかの関数を実行するために使用されるコーダによって与えられるメンバーです.
機能の下に存在するボディは、アプリケーションに実行するために必要な全体の計算と処理がここで書かれる重要な役割です.
Python言語の関数の例
15
Javaでの同じプログラム
15
解説
Javaでは、クラス名なしで直接関数を書くことはできません.また、クラス名なしでPythonで関数を書くこともできます.したがって、Pythonでは各関数を簡単にテストして、他のプログラミング言語に比べて大きな利点があります.
Pythonでは、プログラミング言語で使用される変数のデータ型を指定する必要はありません.しかし、変数を使用するすべての場所ごとにデータ型を与える必要があります.
以下のようになります:
文法
関数を定義する簡単な構文です.
def name(parameters):
pass#body code to perform function as required for you:
このDEFキーワードではPythonプログラミング言語の関数を定義するために使用されます.そのほとんどのプログラム言語では、それぞれの関数の本体を定義するために使われます.パラメータは、その値を使用していくつかの関数を実行するために使用されるコーダによって与えられるメンバーです.
機能の下に存在するボディは、アプリケーションに実行するために必要な全体の計算と処理がここで書かれる重要な役割です.
Python言語の関数の例
def sum(a , b):
sum=a + b #adding two numbers
return sum #returning the sum of numbers
add=sum(10,5) #initializing parameters by calling the function from #outside
print(add) #it will print the returned values from function.
出力:15
Javaでの同じプログラム
public class sum
{
public static void main(String args[]){
int a=10;//initializing value of a to be 10 of datatype integer
int b=5;//initializing value of b to 5 of datatype integer
System.out.println(add(a , b));//sends the values of a and b and print the values for the calculations done in program.
}
public static int add(int a ,int b){
int sum =a + b; //adds the values of a and b and store the value in sum variable of integer datatype.
return sum;
}
}
出力:15
解説
Javaでは、クラス名なしで直接関数を書くことはできません.また、クラス名なしでPythonで関数を書くこともできます.したがって、Pythonでは各関数を簡単にテストして、他のプログラミング言語に比べて大きな利点があります.
Pythonでは、プログラミング言語で使用される変数のデータ型を指定する必要はありません.しかし、変数を使用するすべての場所ごとにデータ型を与える必要があります.
以下のようになります:
int
long
float
double
char
byte
string
array
Reference
この問題について(Python関数), 我々は、より多くの情報をここで見つけました https://dev.to/rupeshdarimisetti/python-function-brief-1m0eテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol