Hi Pythoners...
It seems to me the Asterisk (*) sign in python means many things...
if a python code line looks like this:
def__init__(self, func, *param):
bla bla bla...
and then u have something like this:
func(*param)
and then something like this:
def Wrapper(select, func, param):
bla bla bla...
I took this section of code from the 'Python Cookbook' textbook page
223 about 'Running Functions in the future'...
I just cant figure out what is the asterisk (*) sign for and what is
the different between *param and param??
Many thanks Pythoners...
Regards
sarmin 3 4112
"sarmin" <sa********@yahoo.com> wrote in message
news:ma*************************************@pytho n.org... Hi Pythoners...
It seems to me the Asterisk (*) sign in python means many things...
if a python code line looks like this: def__init__(self, func, *param): bla bla bla...
and then u have something like this: func(*param)
and then something like this: def Wrapper(select, func, param): bla bla bla...
I took this section of code from the 'Python Cookbook' textbook page 223 about 'Running Functions in the future'...
I just cant figure out what is the asterisk (*) sign for and what is the different between *param and param??
Many thanks Pythoners...
Regards sarmin
It's for variable length parameter lists. In a function
definition, one * is a list of additional positional
parameters, two **s is a dictionary of additional
keyword parameters.
In a function call, one * is a list of additional
positional parameters, two **s is a dictionary
of additional keyword parameters.
John Roth
At some point, "John Roth" <ne********@jhrothjr.com> wrote: "sarmin" <sa********@yahoo.com> wrote in message news:ma*************************************@pytho n.org... Hi Pythoners...
It seems to me the Asterisk (*) sign in python means many things...
if a python code line looks like this: def__init__(self, func, *param): bla bla bla...
and then u have something like this: func(*param)
and then something like this: def Wrapper(select, func, param): bla bla bla...
I took this section of code from the 'Python Cookbook' textbook page 223 about 'Running Functions in the future'...
I just cant figure out what is the asterisk (*) sign for and what is the different between *param and param??
Many thanks Pythoners...
Regards sarmin
It's for variable length parameter lists. In a function definition, one * is a list of additional positional parameters, two **s is a dictionary of additional keyword parameters.
In a function call, one * is a list of additional positional parameters, two **s is a dictionary of additional keyword parameters.
Don't forget multiplicaton:
2 * 2
and power
2 ** 2
:-)
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Hi Sarmin, and then u have something like this: func(*param)
[...] I just cant figure out what is the asterisk (*) sign for and what is the different between *param and param??
The asterisk is used for multiple parameters, which are passed to
the function as a tuple.
If your function might be called with a varying number of arguments:
myfunc(10)
or
myfunc(10, 20, 30)
or
myfunc(10, "ten", 20, "twenty")
you could write it as:
def myfunc(*param):
print param
and you would get myfunc(10)
(10,) myfunc(10, 20, 30)
(10, 20, 30) myfunc(10, "ten", 20, "twenty")
(10, 'ten', 20, 'twenty')
If you had defined your function without the
asterisk, you could only use a single parameter:
def myfunc(param):
print param
myfunc(10)
10 myfunc(10, 20, 30)
Traceback (most recent call last):
File "<pyshell#27>", line 1, in -toplevel-
myfunc(10, 20, 30)
TypeError: myfunc() takes exactly 1 argument (3 given)
You can have non-optional parameters before the asterisk parameter:
def myfunc(required, necessary, *optional):
print "required", required
print "necessary", necessary
print "optional", optional
myfunc(10, 20, 30, 40)
required 10
necessary 20
optional (30, 40) myfunc(10)
Traceback (most recent call last):
File "<pyshell#35>", line 1, in -toplevel-
myfunc(10)
TypeError: myfunc() takes at least 2 arguments (1 given)
Regards, Myles. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sarmin kho |
last post by:
Hi Pythoners...
I am definitely confused with the use of asterisk (*) sign in python...
I quoted the following code from 'python cookbook' text book page 223 about 'running functions in the...
|
by: Mark Hahn |
last post by:
We are considering switching to the dollar sign ($) for self, instead of the
period ( . ) we are using now in Prothon. Ruby uses the at-sign (@) for
self, but our new usage of self also includes...
|
by: garett |
last post by:
Hello, I have been reading text processing in python and in the appendix
the author describes:
>>> sides =
>>> zip(*zip(*sides))
what is this asterisk-list syntax called? Any suggestions for...
|
by: Robert M |
last post by:
Hello,
I am having a problem when I enter a new row using data grid footer and the
data contains asterisk ('). I can use replace function, and it will not
crash the program but it shows 2...
|
by: Evan |
last post by:
I am trying to put an asterisk in the Label text property but the asterisk
doesn't show up in the correct place.
If I enter "* hello" in the text property (using the designer property
pages) the...
|
by: selvarani |
last post by:
Hi all,
I am a newbie to Asterisk and PHP. I have installed wamp5_1.4.3 and working with PHP on this. I would like to write a PHP script to interact with asterisk. Where are the Manager API's...
|
by: striker07 |
last post by:
Someone help me how can i display a diamond shaped asterisk correctly pls. correct my program
this is my code:
Dim ctr, space, asterisk As Integer
For ctr = 1 To 9 Step 2
For space = (9...
|
by: Coll |
last post by:
I'm working with a form & a query that allows the user to filter the
data using several combo boxes. One of the combo boxes allows them to
select the first letter of a a particular field, and it...
|
by: Phillip B Oldham |
last post by:
Are there any FOSS Python Single-Sign-on Servers?
We're looking to centralise the sign-on for our numerous "internal"
webapps (across multiple servers, languages, and domains) to speed
user...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |