• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Python » map() Function in Python
Next →
← Prev

map() Function in Python

By Dinesh Thakur

Python’s map() is a built-in function that executes a specified function on all the elements of an iterator and returns a map object (an iterator) for retrieving the results. The elements are sent to the function as a parameter. An iterator, for example, can be a list, a tuple, a string, etc., and it returns an iterable map object.

map function in pythonSyntax of map function in python

The syntax for the map() function is as follows:

Syntax: map(function, iterable[, iterable1, iterable2,.., iterableN])

Parameters :

• Function: A mandatory function that will be applied to all the elements of a given iterable.
• Iterable: It is iterable and must be mapped. It could be a list, a tuple and so on. Many iterator objects may be passed to the map() function.

Return Value

The function map() applies a given function to every element of an iterable and returns an iterable map object, i.e. a tuple, a list, etc.

Python map() example

Let’s write a function to be used with map() function.

#function to square the value passed to it

def square(x): 
return x * x

It’s a simple function that returns the square of the input object.

#creating a list
my_list = [1, 2, 3, 4, 5]
result = map(square, my_list)
#prints a list containing the square values
print(result) 

The map() function takes the square function and my_list iterable. Any element in my_list is passed by map() to square function.

The function will print iterator elements with white space.

Python map() Function Example Using a Lambda Function

The first argument for map() is a function, which we use to apply to each element. For each aspect of the iterable, Python calls the function once and returns the manipulated element to a map object.

The syntax of map() with a lambda function is as follows:

map(lambda argument(s): expression)

We may implement a lambda function for a list like below with an expression we would like to use for each object in our list:

n = [5, 10, 15, 20, 25, 30]

We may use map() and lambda to use an expression against any of our numbers.

mapped = list(map(lambda x: x * x, n))

We declare elements here as x in our list. And we multiply by the same element. We move our number list as the map() iterable.

We print a listing of the map object to get the results immediately:

print(mapped)

Complete Program and output:

map with a lambda function program

You’ll also like:

  1. Lambda Function in Python
  2. What is Python? | Introduction to Python Programming
  3. Python Features | Main Features of Python Programming Language
  4. Python Operators and Operands – Types of Operators in Python
  5. Write A C++ Program To Add, Subtract And Multiply Two Numbers By Using The Function Within Function Concept (Nesting Of Function).
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Python

Python Tutorials

  • Python - Home
  • Python - Features
  • Python - Installation
  • Python - Hello World
  • Python - Operators Types
  • Python - Data Types
  • Python - Variable Type
  • Python - Switch Case
  • Python - Line Structure
  • Python - String Variables
  • Python - Condition Statement
  • Python - if else Statement
  • Python - for-loop
  • Python - while loop
  • Python - Command Line
  • Python - Regular Expression

Python Collections Data Types

  • Python - List
  • Python - Sets
  • Python - Tuples
  • Python - Dictionary

Python Functions

  • Python - Functions
  • Python - String Functions
  • Python - Lambda Function
  • Python - map() Function

Python Object Oriented

  • Python - Oops Concepts
  • Python - File Handling
  • Python - Exception Handling
  • Python - Multithreading
  • Python - File I/O

Python Data Structure

  • Python - Linked List
  • Python - Bubble Sort
  • Python - Selection Sort
  • Python - Linear Search
  • Python - Binary Search

Python Programs

  • Python - Armstrong Number
  • Python - Leap Year Program
  • Python - Fibonacci Series
  • Python - Factorial Program

Other Links

  • Python - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW