Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Python programming language Functions

Posted on August 6, 2017January 21, 2020

Table of Contents

  • Python programming language functions
      • The return ststement

Python programming language functions

In this tutorial, we will discuss the concept of Python programming language functions.

In python, function is a collection of related and reusable statements include as a single unit. This is used to perform a specific action that looks like a method.

Basically two type of functions are available in python.

1. Built-in function – this functions defines and it is a built-in python programming language.
For Examples – Math function, String function
2. User- defined function – Users can define the function themselves.

This tutorial explains user defined functions

The advantages of using functions are:

  • clearly understanding code
  • reducing duplication in code
  • reuse of code
  • Information hiding


Syntax of python function

Python programming language Functions
Syntax
About user-defined function
  • A function created with the def keyword in python that is used to identify the start of the function.
  • function_name is used to uniquely identify every function.
  • Parameters and arguments are used to pass variables and values to function but parameter passing is optional (it is not compulsory).
  • A colon mark is used to identify the end of the function.

Example of function

We can demonstrate about python function usingthe following examples

Program 1

How to create simple “hello world” program using python function

Python programming language Functions
Example
When the above code is executed, it produced the following results.
Hello world


Program  2

Python programming language Functions
Example
When the above code was executed, it produced the following results
hello i am a function
hello i am a function
hello i am a function

Program 3

When the above code was executed, it produced the following results

hello i am a function


Program 4

 
When the above code was executed, it produced the following results
 hello mohan

hello kanthan
hello Nimal
hello Santhan

Program 5

When the above code was executed, it produced the following results
hay kamalan
Program 6
When the above code was executed, it produced the following results
 
10
 
Program 7
 
Function with argument
 
Python programming language Functions
Python
When the above code was executed, it produced the following results
10
62
67
60
Program 8
When the above code was executed, it produced the following results
(‘my first name is’, ‘logan’)
(‘my last name is’, ‘Mohan’)
(‘my age is’, 34)
(‘my sex is’, ‘M’)

The return ststement

We can use the return statement in Python
Syntex of return statement
return[expression_list]
Example 1
 
Example 2
When the above code was executed, it produced the following results
25
Example 3
 
When the above code was executed, it produced the following results
25
250
Default in python function
 
Program 1
Output
 
2 5
Program 2
 
Output
 
87 12.9 12 kannan
 
Program 3
Output
 
87 12.9 24 vannan
 
Find volume in a round shape
 
Output
 
33.5103216383
 
 
 
 
Suggested for you
Function in C programming language
String function in C language
Arithmetic function in C language
Method in Java language
Python language methamatical function
C++ programming methamatical function
 





Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes