Python Fastlane Crash Course: The Smart Way To Learn Python Proramming by Goldmeyr Martin
Author:Goldmeyr, Martin [Goldmeyr, Martin]
Language: eng
Format: epub
Published: 2020-03-30T16:00:00+00:00
That is how we can have a basic Python function.
Function Parameters
You can dynamically define arguments for a function. Example:
#!/usr/bin/python3
def getSum(p, q):
result = p + q
print('The first number is', p)
print('The second number is', q)
print("The sum is", result)
getSum(19,10)
The code returns the following result:
We defined a function named getSum . The function takes two parameters, namely p and q . We have another variable named result, which is the sum of the two function parameters. In the last statement, we have called the function and passed the values for the two parameters. The function will calculate the value of the variable result by adding the two numbers. We finally get the result shown above.
Note that during our function definition, we specified two parameters, p and q. Try to call the function will either more than two parameters or 1 parameter and see what happens. Example:
#!/usr/bin/python3
def getSum(p, q):
result = p + q
print('The first number is', p)
print('The second number is', q)
print("The sum is", result)
getSum(19)
In the last statement in our code above, we have passed only one argument to the function, that is, 19. The program gives an error when executed:
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.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8304)
Test-Driven Development with Java by Alan Mellor(6741)
Data Augmentation with Python by Duc Haba(6659)
Principles of Data Fabric by Sonia Mezzetta(6410)
Learn Blender Simulations the Right Way by Stephen Pearson(6305)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6178)
Hadoop in Practice by Alex Holmes(5961)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5809)
RPA Solution Architect's Handbook by Sachin Sahgal(5575)
Big Data Analysis with Python by Ivan Marin(5372)
The Infinite Retina by Robert Scoble Irena Cronin(5266)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5152)
Pretrain Vision and Large Language Models in Python by Emily Webber(4339)
Infrastructure as Code for Beginners by Russ McKendrick(4100)
Functional Programming in JavaScript by Mantyla Dan(4040)
The Age of Surveillance Capitalism by Shoshana Zuboff(3959)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3813)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3616)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3591)
