Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66954
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!peer03.am1!peering.am1!npeersf04.am4!fx25.am4.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset=us-ascii; format=flowed; delsp=yes |
| Newsgroups | comp.lang.python |
| Subject | Re: Functions help |
| References | <mailman.7276.1393141556.18130.python-list@python.org> |
| MIME-Version | 1.0 |
| Content-Transfer-Encoding | 8bit |
| From | "Rhodri James" <rhodri@wildebst.org.uk> |
| Organization | The Wildebestiary |
| Message-ID | <op.xbrg4dgo5079vu@gnudebeest> (permalink) |
| User-Agent | Opera Mail/12.16 (Linux) |
| Lines | 34 |
| NNTP-Posting-Host | 81.97.70.240 |
| X-Complaints-To | http://netreport.virginmedia.com |
| X-Trace | 1393203675 81.97.70.240 (Mon, 24 Feb 2014 01:01:15 UTC) |
| NNTP-Posting-Date | Mon, 24 Feb 2014 01:01:15 UTC |
| Date | Mon, 24 Feb 2014 01:01:15 -0000 |
| X-Received-Body-CRC | 947300934 |
| X-Received-Bytes | 1945 |
| Xref | csiph.com comp.lang.python:66954 |
Show key headers only | View raw
On Sun, 23 Feb 2014 05:43:17 -0000, Scott W Dunning <swdunning@cox.net>
wrote:
> I had a question regarding functions. Is there a way to call a function
> multiple times without recalling it over and over. Meaning is there a
> way I can call a function and then add *5 or something like that?
The usual way to call a function several times is to use a loop, like this:
for i in range(5):
my_function()
The function "range" returns the sequence of numbers 1, 2, 3, 4 and 5 [*],
so this has the same effect as if you had typed:
my_function()
my_function()
my_function()
my_function()
my_function()
This isn't a great advantage if you just want to call the function two or
three times, but when you want to call it two or three hundred times it
matters a lot more! You can still use the same technique if you want to
pass different parameters to the function each time you call it:
for i in range(6):
print(i*i)
for day in ("Mon", "Tue", "Wed", "Thu", "Fri"):
do_stuff_for_day(day)
--
Rhodri James *-* Wildebeest Herder to the Masses
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-22 22:43 -0700
Re: Functions help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 08:44 +0000
Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 10:55 +1000
Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 01:09 +0000
Re: Functions help alex23 <wuwei23@gmail.com> - 2014-02-24 11:39 +1000
Re: Functions help Benjamin Kaplan <benjamin.kaplan@case.edu> - 2014-02-23 18:55 -0800
Re: Functions help Grant Edwards <invalid@invalid.invalid> - 2014-02-24 15:38 +0000
Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 03:21 +0000
Re: Functions help rurpy@yahoo.com - 2014-02-23 20:01 -0800
Re: Functions help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 13:59 +0000
Re: Functions help Ethan Furman <ethan@stoneleaf.us> - 2014-02-25 18:52 -0800
Re: Functions help rurpy@yahoo.com - 2014-02-26 17:06 -0800
Re: Functions help MRAB <python@mrabarnett.plus.com> - 2014-02-24 03:36 +0000
Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:43 -0700
Re: Functions help Roy Smith <roy@panix.com> - 2014-02-23 20:28 -0500
Re: Functions help Travis Griggs <travisgriggs@gmail.com> - 2014-02-23 17:27 -0800
Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-24 01:01 +0000
Re: Functions help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-24 21:18 -0500
Re: Functions help "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-27 22:49 +0000
Re: Functions help Scott W Dunning <swdunning@cox.net> - 2014-02-23 18:24 -0700
Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:15 -0800
Re: Functions help sffjunkie@gmail.com - 2014-02-24 02:32 -0800
csiph-web