Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:24:19+00:00 2026-06-09T02:24:19+00:00

For a normal function, map works well: def increment(n): return n+1 l = [1,

  • 0

For a normal function, map works well:

def increment(n):
    return n+1
l = [1, 2, 3, 4, 5]
l = map(increment, l)
print l
>>> [2, 3, 4, 5, 6]

However, if it’s print being put inside the map function:

l = [1, 2, 3, 4, 5]
l = map(print, l)
print l

python will complain:

l = map(print, l)
            ^
SyntaxError: invalid syntax

What makes print special? Doesn’t print(x) also a valid function call? The above code are tested under python 2.7.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:24:21+00:00Added an answer on June 9, 2026 at 2:24 am

    In Python 2.x, print is a statement, not a function. If you try this in Python 3.x it will work.

    In Python 2.x, you can say print(x) and it is not a syntax error, but it isn’t actually a function call. Just as 1 + (3) is the same as 1 + 3, print(x) is the same as print x in Python 2.x.

    In Python 2.x you can do this:

    def prn(x):
        print x
    

    Then you can do:

    map(prn, lst)
    

    and it will work. Note that you probably don’t want to do lst = map(prn, lst) because prn() returns None, so you will replace your list of values with a same-length list of just the value None.

    EDIT: Two other solutions for Python 2.x.

    If you want to completely change the behavior of print, you can do this:

    from __future__ import print_function
    
    map(print, lst)
    

    This makes print into a function just as it is in Python 3.x, so it works with map().

    Or, you can do this:

    from pprint import pprint
    
    map(pprint, lst)
    

    pprint() is a function that prints things and it is available as a built-in. I’m not exactly sure how it is different from the default print (it says it is a “pretty-print” function but I’m not sure how exactly that makes it different).

    Also, according to the PEP 8 standard, it is non-recommended to use l as a variable name, so I am using lst instead in my examples.

    http://www.python.org/dev/peps/pep-0008/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

why this return 5,I'm curious about this the normal function have higher priority over
I've just started learning Clojure, if I define the following map: (def distributions {:normal
I have a template class, inside which i have a normal function. But i
I need to do: I am using the normal auto-fill function in Excel (double
If I have a jQuery plugin using the normal standard of: (function( $ ){
I have a function that generates normal random number matrix having normal distribution using
I'm writing a small function to generate values from the Normal distribution using Box-Muller
NET library that calculates the inverse erf() function in the normal distribution? Do you
I have a function that returns log10 values. On converting them to normal numbers,
I have a function Process(data, f) where data is a normal parameter and f

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.