DEV Community

Rupesh-Darimisetti
Rupesh-Darimisetti

Posted on • Updated on

python function brief

python is a powerful programming language and simple in language as we speak everyday. with python programming language one can do any sort of task and applications present in software and IT field.

Syntax:
it as simple syntax to define function i.e.

def name(parameters):
     pass#body code to perform function as required for you:

Enter fullscreen mode Exit fullscreen mode

in this def keyword is used to define the function in python programming language, every programming languages most of then uses flower brackets({}) are used to define the body of that function here colon(:) is used as it and indentation i.e. space in line from staring of the function defines the body of the function.

parameters are the members given by coder which will be used to perform some function using that values.

body present below the function is the key role where the total calculation and processing that is necessary for the application to be performed is written here.

example of function in python language:

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.
Enter fullscreen mode Exit fullscreen mode

output:
15

same program in 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;
}
}
Enter fullscreen mode Exit fullscreen mode

output:
15

explanation:
in java one cannot write function directly without class name and one can write the function in python without class name also so its a big advantage to test each function easily in python then compared to other programming language.

in python one must not necessary to give the datatype of variables used in programming language. but it is necessary to give the datatype for each and every place you use variable the datatype has to be used in other programming languages.
they are:

int
long
float
double
char
byte
string 
array

Enter fullscreen mode Exit fullscreen mode

Top comments (0)