Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'argument': 0.05; 'def': 0.12; 'subject:make': 0.16; 'header:User-Agent:1': 0.23; 'function': 0.29; 'subject:the': 0.34; 'received:google.com': 0.35; 'received:10': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=rqgbYB2Us7DQmuWvouVPK8lxUQIoaNRKIxeMJK9OjMs=; b=wP45Wqq6vbXEodCas7JaN2HKQrDnvFCi/I0fYVuJKBxhnshdOmX8kaIb1Qn/roD5ji Lj0MPRcZfqlEoHQzLcZjowpsiNKiDrx/WYDaS8mqzJnn/Yp0XtTuQ4fedXNrD1EBBGmq tHQnlGU6kmaYIYI73zRXKIf447zslKk76lqhBskFeIGLK6sguXXWhG+SLa9Z03GCA7he p39u7GGd8O5xqgToiPt0gmVglTChCIR8BPIMmS834uQVl2xmsauWqcnUQ6v1uMYZwQoA Ck0etJSBBm/s8xhEcGFH/eASOcobKK0wayoVcpfvYDvDzs66gvflFbUYzlX26aZpANiZ kQcg== X-Received: by 10.67.1.195 with SMTP id bi3mr2573320pad.74.1408001548186; Thu, 14 Aug 2014 00:32:28 -0700 (PDT) Date: Thu, 14 Aug 2014 15:32:19 +0800 From: luofeiyu User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: python-list@python.org Subject: how to write a function to make operation as a argument in the function Content-Type: multipart/alternative; boundary="------------060800050800060200020407" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408002867 news.xs4all.nl 2934 [2001:888:2000:d::a6]:56907 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76279 This is a multi-part message in MIME format. --------------060800050800060200020407 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I want to write a function to make operation as a argument in the function. |def fun(op,x,y): return(x op y)| it is my target for the funciton: if op ="+" fun(op,3,9) =12 if op ="*" fun(op,3,9) =27 How to write it? --------------060800050800060200020407 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

I want to write a function to make operation as a argument in the function.

def  fun(op,x,y):
    return(x op y )

it is my target for the funciton:

if op ="+" fun(op,3,9) =12
if op ="*" fun(op,3,9) =27

How to write it?

--------------060800050800060200020407--