Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Returning Multiple Values in Python using list?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 687
    Comment on it
    # A Python program returning multiple values from a method using list
     
    # Defining a function which returns a list
    
    def fun():
        str = "Demo"
        x = 20  
        return [str, x];  
     
    # Driver code to test above function
    
    list = fun()      //calling of fun()
    print(list)       // printing list returned from function

    Output:

    ['Demo', 20]

    Explanation of above program:

    A list can be defined as comma-separated values (items) between square brackets or simply an array of items in square bracket. The difference between array and list is list can store values of different data types. Lists are immutable i.e values of lists can be updated via indexes or values can be deleted. In above program,a function is defined in which a string and an integer value is defined. The fun() is returning  comma-separated values (items) between square brackets whisch is a list. When fun() is called it's return value is assigned to a list variable, finally printing the list.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: