473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

functions with unlimeted variable arguments...

how can i define a function with variable parameters? For example,

f(a) would return [a]
f(a,b) would return [a,b]
f(a,b,...) would return [a,b,...]

One solution is of course to make the argument as a list. i.e.
f([a,b,...])
but are there other solutions?

Xah
xa*@xahlee.org
∑ http://xahlee.org/

Jul 19 '05 #1
4 1348
"Xah Lee" <xa*@xahlee.org> writes:
but are there other solutions?

Xah


Geez man, haven't you been around long enough to read the manual?

def f(*a): return a
Jul 19 '05 #2
Xah Lee wrote:
how can i define a function with variable parameters? For example,

f(a) would return [a]
f(a,b) would return [a,b]
f(a,b,...) would return [a,b,...]

One solution is of course to make the argument as a list. i.e.
f([a,b,...])
but are there other solutions?
def foo(*args): .... print repr(args)
.... return list(args)
.... foo() ()
[] foo(42) (42,)
[42] foo(666, 'hello', 1.234) (666, 'hello', 1.234)
[666, 'hello', 1.234]


Jul 19 '05 #3
Hi All--

Paul Rubin wrote:

"Xah Lee" <xa*@xahlee.org> writes:
but are there other solutions?

Xah


Geez man, haven't you been around long enough to read the manual?

def f(*a): return a


He's been around long enough to rewrite the manual.

Metta,
<if-he-succeeds-we'll-all-have-to-take-up-perl>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 19 '05 #4
Xah Lee wrote:
oops... it is in the tutorial... sorry.
If you're sorry, have you now *finally* gone and worked through the rest
of tutorial, making a serious attempt to learn it?
This is not a rhetorical question, but where would one start to look
for it in the python ref?

a language is used by programers. Subroutine definition with
variable/default parameters is a basic issue a programer wants to know,
and different languages differs very much in how they handle this. This
is what i mean that the language doc should be programing oriented, as
opposed to computer-sciency or implementation oriented...


You seem to be under the impression that most programmers learn a new
language by looking up key phrases such as "variable argument list" in
the index of their new language's manual as they encounter the need for
a feature.

In actual fact, most programmers learn by finding a tutorial or
convenient beginner's lesson (hint hint), and then by browsing through
other material such as a FAQ (hint hint), and then perhaps by skimming
quickly through the reference material to learn what is there. This way
they avoid making themselves look like complete and utter fools by
appearing to learn only by looking up things in the index.

-Peter
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
9
by: Gibby Koldenhof | last post by:
Hiya, Terrible subject but I haven't got a better term at the moment. I've been building up my own library of functionality (all nice conforming ISO C) for over 6 years and decided to adopt a...
1
by: S?ren Gammelmark | last post by:
Hi I have been searching the web and comp.lang.c of a method of using variable-argument function pointers and the like. And some of the questions arising in this post are answered partly in...
5
by: Sathyaish | last post by:
I knew this but I have forgotten. How do you declare a function that has to accept a variable number of arguments? For instance, the printf() function has a variable number of arguments it can...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
2
by: Alan | last post by:
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of...
9
by: oldyork90 | last post by:
I'm going thru code and have never seen this before http://www.webreference.com/programming/javascript/mk/column2/3.html Look at function CreateDragContainer() on line 25. It has no arguments...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.