Scientific Computing with Python 3 by 2nd Revised Edition (2016)
Author:2nd Revised Edition (2016)
Language: eng
Format: epub, azw3
Publisher: Packt Publishing
Access to variables defined outside the local namespace
Python allows functions to access variables defined in any of its enclosing program units. These are called global variables, in contrast to local variables. The latter are only accessible within the function. For example, consider the following code:
import numpy as np # here the variable np is defined def sqrt(x): return np.sqrt(x) # we use np inside the function
This feature should not be abused. The following code is an example of what not to do:
a = 3 def multiply(x): return a * x # bad style: access to the variable a defined outside
When changing the variable a the function, multiply tacitly changes its behavior:
a=3 multiply(4) # returns 12 a=4 multiply(4) # returns 16
It is much better in that case to provide the variable as a parameter through the argument list:
def multiply(x, a): return a * x
Global variables can be useful when working with closures. Namespaces and scopes are discussed more extensively in Chapter 11, Namespaces, Scopes, and Modules.
Download
Scientific Computing with Python 3 by 2nd Revised Edition (2016).azw3
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26532)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19015)
The Fifty Shades Trilogy & Grey by E L James(18969)
Shot Through the Heart by Mercy Celeste(18885)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(16993)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16885)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16810)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16708)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16336)
The Subtle Art of Not Giving a F*ck by Mark Manson(14273)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14076)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13442)
Scorched Earth by Nick Kyme(12718)
Drei Generationen auf dem Jakobsweg by Stein Pia(10926)
Suna by Ziefle Pia(10851)
Scythe by Neal Shusterman(10278)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9483)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9320)
This is Going to Hurt by Adam Kay(9110)
