Learn Python Episode #15: User-Defined Functions

Publicado em: 11 Agosto 2017
no canal de: 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  


Nesta página do site você pode assistir ao vídeo on-line Learn Python Episode #15: User-Defined Functions duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Joseph Delgadillo 11 Agosto 2017, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 3,415 vezes e gostou 45 espectadores. Boa visualização!