Types Of Python Variables

in python •  6 months ago 

Hello everyone!

1000015904.jpg

Let us learn about the type of python variables with an example.

1000004785.jpg

Types of Python Variables :-

1} Local Variable :
The variables that are declared within the function and have scope within the function are known as local variables.

  • Example -
    def add():
    a=20
    b=30
    print ("The sum is", c)
    add()
    ~ Output: The sum is 50.

2} Global Variable :
The variables that are declared outside the function serves as global variable.
They can be used inside or outside the function.

  • Example -
    x=|0|
    def main function ():
    global x
    print (x)
    x='Welcome'
    print (x)
    main function
    print (x)
    ~ Output:
    |0|
    Welcome
    Welcome

1000006887.png

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!