Python 101 by Mihai Catalin Teodosiu

Python 101 by Mihai Catalin Teodosiu

Author:Mihai Catalin Teodosiu
Language: eng
Format: epub
Tags: python, python programming, python 3, python crash course, learn python, python 101, python coding, python developer, python development, python for beginners
Publisher: Mihai Catalin Teodosiu


my_first_function()

This is our first function!

We basically created the help section for this function by using a docstring.

Inside a function, all the syntax rules of Python apply as you've learned up to this point in the book. Whether you're using for or while loops, if/elif/else blocks, dictionaries or list indexing and slicing inside your function, the exact same syntax rules apply.

Now, I mentioned earlier that functions are reusable blocks of code. Let's see why. After defining a function, with or without any parameters inside the parentheses, we can call that function whenever we need to run the code inside it. In order to call a function, you just need to type in that function's name, followed by the parentheses and that's it. Let's see this in action.

So, we have the my_first_function() function already defined. Let's call it inside the Python interpreter.

>>> my_first_function()

Hello Python!

>>> my_first_function()

Hello Python!

>>> my_first_function()

Hello Python!

As you can notice, each time we call the function the code inside that function gets executed. Of course, this is a very basic example of a function, but it should give you an overall understanding of this concept.

Another advantage of functions is that you can change the code within a function and see the results changing as well, the next time you call that function. Therefore, we can say that functions are dynamic structures. Let's redefine our function and change the code inside it. Then, on the next function call, the result should reflect the update we've just made.

def my_first_function():

print("Hello Java!")



Download



Copyright Disclaimer:
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.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(55937)
What's Done in Darkness by Kayla Perrin(26542)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19018)
The Fifty Shades Trilogy & Grey by E L James(18988)
Shot Through the Heart by Mercy Celeste(18893)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17015)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16901)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16827)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16738)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16359)
The Subtle Art of Not Giving a F*ck by Mark Manson(14287)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14084)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13473)
Scorched Earth by Nick Kyme(12723)
Drei Generationen auf dem Jakobsweg by Stein Pia(10930)
Suna by Ziefle Pia(10856)
Scythe by Neal Shusterman(10292)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9489)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9332)
This is Going to Hurt by Adam Kay(9118)