Home > Backend Development > PHP Tutorial > php函数转为python函数

php函数转为python函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:19:35
Original
2261 people have browsed it

函数如下:

<code>function ChangeWord($keyword, $value, $changfun) {
    return is_callable($changfun) ? call_user_func($changfun, $keyword, $value) : $changfun;
}</code>
Copy after login
Copy after login

回复内容:

函数如下:

<code>function ChangeWord($keyword, $value, $changfun) {
    return is_callable($changfun) ? call_user_func($changfun, $keyword, $value) : $changfun;
}</code>
Copy after login
Copy after login

import types
import sys

def change_word(keyword, value, change_func):
    if callable(change_func):
        return change_func(keyword, value)
    else:
        return change_func

def test(keyword, value):
    print keyword
    print value

if __name__ == '__main__':
    change_word('hello', 'world', test)
    change_word('goodbye', 'world', lambda keyword,value: sys.stdout.write('%s, %s' % (keyword, value)))

Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template