Learn Python Episode #15: User-Defined Functions

Veröffentlicht am: 11 August 2017
auf dem Kanal: 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  


Auf dieser Seite können Sie das Online-Video Learn Python Episode #15: User-Defined Functions mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Joseph Delgadillo 11 August 2017 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,415 Mal angesehen und es wurde von 45 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!