473,761 Members | 10,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asterisk sign in python

Hi Pythoners...

It seems to me the Asterisk (*) sign in python means many things...

if a python code line looks like this:
def__init__(sel f, 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
Jul 18 '05 #1
3 4140
"sarmin" <sa********@yah oo.com> wrote in message
news:ma******** *************** **************@ python.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__(sel f, 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

Jul 18 '05 #2
At some point, "John Roth" <ne********@jhr othjr.com> wrote:
"sarmin" <sa********@yah oo.com> wrote in message
news:ma******** *************** **************@ python.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__(sel f, 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)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #3
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#2 7>", 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#3 5>", line 1, in -toplevel-
myfunc(10)
TypeError: myfunc() takes at least 2 arguments (1 given)
Regards, Myles.
Jul 18 '05 #4

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

Similar topics

1
2550
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 future'... it says: def __init__(self,func, *param): bla bla bla... then it says:
29
22189
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 replacing the period for some attribute references, as in obj$func() versus obj.func(), and too many programs treat that as an email address and screw it up. Also the S in the symbol $ reminds one of the S in $elf. Can people from outside the...
1
2204
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 finding more information about it? Thanks. -Garett
3
1473
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 asterisk (' '). Actually it does not happen in all footers and I can not find what is the difference, unless I turn some property true... Help is very much appreciated Thank u
2
2615
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 label is displayed as "hello *". If I enter "3 * hello" the label is displayed as "hello * 3". How I get the asterisk to display in the proper location? Thanks in advance.
0
1526
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 used. How come the PHP script and Asterisk Manager API's interact? What should the script do exactly? Anyone help me out. Thanks in advance.
1
19027
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 - 2) / 2 To 0 LstDisplay.AddItem (" ") Next For asterisk = 1 To ctr
2
9156
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 will use that first letter in the criteria of the query to include only records with a value beginning with that letter. The tricky part is that one of the possible values for that field is - *.* - not values I would have chosen, but they are...
9
4336
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 management and application development. I've searched around but can only seem to find OpenID servers, which will probably be too "open" for our needs. Coding one up would possibly take more time than we have, and we'd prefer something maintained...
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.