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 19, 2026

Table of Contents

  • Python programming language functions
    • Syntax of python function
    • Example of function We can demonstrate about python function using the following examples Program 1 How to create simple “hello world” program using python function
    • Function with argument
      • The return ststement
    • Default in python function
    • Related

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.

Python programming language Functions
Python programming language Functions

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 using the 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
Python programming language Functions
Python Functions
When the above code was executed, it produced the following results
 
10
 
Program 7
 

Function with argument

 
Python programming language Functions
Python Functions
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 mathematical function
C++ programming mathematical function
 Function in Python language

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes