Learn Python Episode #15: User-Defined Functions

Pubblicato il: 11 agosto 2017
sul canale di: Joseph Delgadillo
3,415
45

Learn Python programming and more with our Learn to Code course Bundle!
⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠https://josephdelgadillo.com/product/...

Let's get into user-defined functions. Now, every programming language has functions, however they are going to look different depending on the language. If you have any experience with PHP or JavaScript, functions in Python are going to look similar. So, we are now past the need to use terminal, and from here on out we are going to use our IDE. In addition to functions, we are going to cover a few of the PEP guidelines. PEP is basically a style guide for the Python language, and the first thing we need to do is drop down two lines from the top of the script. To begin defining a function in Python, all you need to do is type the word "def". When naming functions we must be mindful of the PEP guidelines. With Python you will be using snake case, words separated with underscores, when naming your function.

def my_function():

Within the parenthesis we can pass parameters into our function, then we end the line with a colon. So, now we have a function but it doesn't perform any actions, yet.

def my_function():
print("This is my function!")
print("A second string.")

my_function()

Now our function will print out two strings. Notice that our IDE automatically indents 4 spaces. When you indent in Python you are creating block of code. When we skip a line and remove the indentation, we are telling Python that our function is completed. Lastly, we will call our function. In the next video we will talk about arguments and how use them inside your function.

Web - https://josephdelgadillo.com
Subscribe - https://bit.ly/SubscribeJTD
Facebook -   / delgadillojt  


In questa pagina del sito puoi guardare il video online Learn Python Episode #15: User-Defined Functions della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Joseph Delgadillo 11 agosto 2017, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 3,415 volte e gli è piaciuto 45 spettatori. Buona visione!