Questions tagged [default-parameters]

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

366 questions
0
votes
0 answers

parameter gather is not used

import pandas as pd import os import time from datetime import datetime path = "/Users/tommasomasaracchio/Documents/pythonfolder" def key_stats(gather="Total Deb/Equity (mrg)"): statspath = path + '/KeyStats' stock_list = [x[0] for x in…
fieshf
  • 1
  • 1
0
votes
2 answers

How do I pass a default parameter to a sub-function in a Pythonic way?

(EDITED FOR CLARITY) I am trying to solve this issue with passing default parameters. I have functions creating plots with matplotlib. These functions accept parameters and some of those have default values: def radar_with_CI(values, categories,…
0
votes
1 answer

Are there caveats of using mutable types as default parameters in functions in Python?

I have recently read about mutable default parameters in Python. For some reason, I came up with an idea of using it like this: data = [3, 4, 1, 8, 5, 9, 2, 6, 7] def get_min(checked=[]): global data mn = min((x for x in data if x not in…
Oleksandr Novik
  • 489
  • 9
  • 24
0
votes
2 answers

Best way to succinctly evaluate default parameters in Python?

Relatively new to Python, I find myself having to evaluate a lot of arguments in functions/static methods and I was thinking if there is a user-friendly way to do this, so I ended up writing a function like so: from typing import Any, Optional,…
gkampolis
  • 31
  • 5
0
votes
2 answers

How to use an object as a function parameter in JS?

I created a function that should return an object with user data. I want the function to accept an object as a parameter and I'd like this object to be defined inside the function with all the values pre-defined as default parameters in case they…
uma
  • 13
  • 2
0
votes
2 answers

C++ what happens when 0 is assigned to class variable in constructor

I'm trying to create a smart pointer and stumbled over the code below. Since I'm pretty new to C++, its syntax is yet something I have to get used to. Below you can see the most important part of the code where RC is the reference counter class with…
Scorpia
  • 375
  • 4
  • 15
0
votes
1 answer

How to mockk when a method's default parameters need an injected field?

My class has a method with default parameters whose values are derived from an injected parameter: class Slack @Inject constructor( private val brokerSettings: BrokerSettings ) { fun alert( message: String, responsible: String =…
0
votes
1 answer

Having trouble with None as default parameter

I am trying to understand how None as the default parameter works. I have a function that has 4 parameters, first is non-default followed by 3 parameters that are set =None. Function: send(name, website=None, to_email=None, verbose=False) Calling…
ires
  • 17
  • 4
0
votes
1 answer

Pass a function a variable while assigning it a value in the function argument? Example: myFunction( arr, newArr = [] )

I'm trying to understand what happens when a variable gets assigned a value inside a function's argument list. For example: myFunction(arr, newArr = []) Does this mean I'm initializing newArr within the function declaration? What if I…
ezeYaniv
  • 412
  • 5
  • 18
0
votes
1 answer

Calling a Function with integer [[mayb_unused]] macro and default argument boolean type parameter

I am writing a Function with 2 Parameters, 1st is integer type marked [[maybe_unused]] and 2nd is Boolean Type with Default Argument false. int preOrderTraversial([[maybe_unused]] int searchData, bool forDisplay = false) This is the function…
0
votes
1 answer

Why doesn't passing a function with default parameters to a templatized constructor and storing it using a lambda as std::function work?

Take this simplified example: Command.h: class Command { public: template Command(Func newToExecute) : toExecute([&newToExecute](){newToExecute();}) { } void callFunction(); //defined in Command.cpp -> calls function with…
xeretis
  • 65
  • 1
  • 8
0
votes
0 answers

How to convert a captureless lambda with a default parameter to a function pointer?

I am trying to store a captureless lambda that has a default parameter to a function pointer. I have the below code working for a lambda with a default argument #include int main() { decltype([](int a = 10) { std::cout << a <<…
0
votes
0 answers

Clang static analysis doesn't like default parameter for const string&

I am getting the following error with clang static analyzer. Any ideas? error: reference to type 'const std::string' (aka 'const basic_string') could not bind to an lvalue of type 'const char [1]' 74 int foo(const std::string& data, const…
kdams15
  • 149
  • 6
0
votes
1 answer

Alternating the use of classes/globals with closures in Python

I came across closures in python, and I've been tinkering around the subject. Please Correct me if I'm wrong here, but what I understood for when to use closures (generally) is that it can be used as a replacement of small classes (q1) and to avoid…
Ahmed Alhallag
  • 311
  • 2
  • 11
0
votes
0 answers

Shorten two parameters using default values from the properties of the same object using destructuring

Can the following function (which is inside a class) be shortened: getCurrentMoves(moves = this.state.moves, stepNumber = this.state.stepNumber) { return moves.slice(0, stepNumber); } All I managed to do is to refactor it to the following.…