Skip to main content

Introduction

Parameters allow you to pass data into functions, making them more flexible and reusable. Instead of working with fixed values, functions can process different inputs.

Basic Parameter Syntax

Define parameters inside the parentheses with their type and name:

Key Components

  • Parameter type: int - specifies what type of data the parameter accepts
  • Parameter name: valorUno, valorDos - names used to reference the values inside the function
  • Multiple parameters: Separated by commas

Passing Arguments

When calling a function, provide values (arguments) for each parameter:
Arguments are the actual values you pass when calling a function, while parameters are the variables that receive those values in the function definition.

Different Ways to Use Parameters

Store Result in Variable

Direct String Interpolation

Direct Print

Complete Example

Parameter Order

Positional parameters must be provided in the exact order they are defined. The first argument matches the first parameter, the second argument matches the second parameter, and so on.

Multiple Parameter Types

Functions can accept parameters of different types:

Parameter Examples by Type

Numeric Parameters

String Parameters

Boolean Parameters

Mixed Parameters

Best Practices

  • Use descriptive parameter names that indicate their purpose
  • Limit the number of parameters (ideally 3 or fewer)
  • Order parameters from most to least important
  • Consider using named parameters for functions with many parameters
  • Always specify parameter types for better code clarity
  • Ensure arguments match the expected parameter types
  • Document complex parameter requirements