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(56777)
What's Done in Darkness by Kayla Perrin(26802)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20668)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20444)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20444)
The Fifty Shades Trilogy & Grey by E L James(19302)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19259)
Shot Through the Heart by Mercy Celeste(19128)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17292)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17225)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17073)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16997)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16615)
The Subtle Art of Not Giving a F*ck by Mark Manson(14614)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14307)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13966)
Scorched Earth by Nick Kyme(12963)
Drei Generationen auf dem Jakobsweg by Stein Pia(11146)
Suna by Ziefle Pia(11070)
Scythe by Neal Shusterman(10555)