Kevin

Python Beginner Tutorial 2 - Functions and Variables

Recommended Posts

 

This tutorial covers the creation of basic functions and how to define variables. After watching this video you should be able to define functions with zero or one argument, create variables, and understand the basics of scope in python.
 

Post questions and comments specifically related to this video below.

Share this post


Link to post
Share on other sites

Hello, Your videos are extremely helpful and I learning how to code little by little each day.

I do have a particular question on a part in the video.

At 9:40 of the video, could you re-explain that area to me again? Thanks

Capture.PNG

Share this post


Link to post
Share on other sites

Sure! See the code below with comments and some changed names to make it easier to understand. My bad on that originally.

def main():
	print(aGlobalVariable)

def myPrintFunction(somethingToPrint):
	print(somethingToPrint)
	
# This will not work because aGlobalVariable has not been defined yet
#main() 

# Global variable. Typically defined at the top of the file but does not need to be. That is best practice

aGlobalVariable = "This is a global variable." 

# Call the main function. This will print aGlobalVariable
main() 

# Directly call the print function. This will print aGlobalVariable again to illistrate it is in fact global
print(aGlobalVariable) 

# Define another variable
otherVariable = "Something else" 

# This will print otherVariable by calling our myPrintFunction that then calls the print function.
myPrintFunction(otherVariable) 

Let me know if you need me to clarify anything specifically.

Kevin

Share this post


Link to post
Share on other sites
class Input_PrintFUNC():#i make class 
    pass


def PrintInput():#here i make the func name
    name = input("your name",)#here i make ver i call it name afte it i make input func and with for the user
    #print(name)#here i wont to print the input the  user enter
    print("hello",name,"wallcome","heve good day")
    #print("wallcome")
   # print("heve good day")




PrintInput()#here i call the func from the class

def add(num1,num2):

    num1 = input("num1",)
    num2 = input("num2",)
    return num2+num1

def main():
    myresolt = add(1, 1)
    print(myresolt)

main()

def PrintInput():#here i make the func name
    name =  input ("your name",)#here i make ver i call it name afte it i make input func and with for the user
    #print(name)#here i wont to print the input the  user enter
    print("hello",name,"Welcome Have a great day")
    #print("wallcome")
   # print("heve good day")

PrintInput()#here i call the func



def minos(num1,num2):
    return num1 - num2

def hilok(num1,num2):
    return num1/num2

def plus(num1,num2):
    return num1 + num2

def kafel(num1,num2):
    return num1 * num2

def dubkafel(num1,num2):
    return num1 ** num2






def ExeFunc():
    print(plus(4,2))
    print(minos(4,2))
    print(dev(4,2))
    print(kafel(4,2))
    print(dubkafel(4,2))
ExeFunc()

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...