function-parameter

Python - use list as function parameters

本小妞迷上赌 提交于 2019-11-26 02:32:48
问题 How can I use a Python list (e.g. params = [\'a\',3.4,None] ) as parameters to a function, e.g.: def some_func(a_char,a_float,a_something): # do stuff 回答1: You can do this using the splat operator: some_func(*params) This causes the function to receive each list item as a separate parameter. There's a description here: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists 回答2: This has already been answered perfectly, but since I just came to this page and did not

Why does a function with no parameters (compared to the actual function definition) compile?

北城余情 提交于 2019-11-26 00:35:45
问题 I\'ve just come across someone\'s C code that I\'m confused as to why it is compiling. There are two points I don\'t understand. First, the function prototype has no parameters compared to the actual function definition. Second, the parameter in the function definition does not have a type. #include <stdio.h> int func(); int func(param) { return param; } int main() { int bla = func(10); printf(\"%d\", bla); } Why does this work? I have tested it in a couple of compilers, and it works fine.

How to get function parameter names/values dynamically?

元气小坏坏 提交于 2019-11-25 23:58:14
问题 Is there a way to get the function parameter names of a function dynamically? Let’s say my function looks like this: function doSomething(param1, param2, .... paramN){ // fill an array with the parameter name and value // some other code } Now, how would I get a list of the parameter names and their values into an array from inside the function? 回答1: The following function will return an array of the parameter names of any function passed in. var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/