Absolute Beginner's Python Programming by Unknown
Author:Unknown
Language: eng
Format: epub
Publisher: Elluminet Press
Published: 2023-05-12T10:10:03+00:00
A variable created in the main body of the Python code is a global variable and belongs to the global scope. Global variables are available from within any scope, global and local.
The period in which a variable exists in memory is called its lifetime.
Variables defined inside a function exist only while the function executes. Once the function returns, the variables inside the function are destroyed.
Recursion
A recursive function is a function that can call itself. This enables the function to repeat itself several times.
Open the file recursion1.py. Here we have a recursive function that calculates the factorial of a number. Remember, to calculate the factorial you multiply all the numbers from 1 to the given number.
def factorial(n):
if n <= 1:
return 1
else:
return n * factorial(n-1)
When we call the factorial function and pass a positive integer (n)
factorial(4)
It will recursively call itself by decreasing the number passed to the function (n) by one each time, then add the call to a call stack.
Download
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.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9422)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9388)
The Mikado Method by Ola Ellnestam Daniel Brolund(9352)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7894)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7440)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7413)
Grails in Action by Glen Smith Peter Ledbrook(7332)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7161)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6006)
Kotlin in Action by Dmitry Jemerov(4683)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3990)
Functional Programming in JavaScript by Mantyla Dan(3742)
Windows APT Warfare by Sheng-Hao Ma(3098)
Learning Java by Patrick Niemeyer & Daniel Leuck(2890)
Mastering Python for Finance by Weiming James Ma;(2879)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2865)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(2791)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2688)
Mastering Java 9 by Dr. Edward Lavieri(2584)