All fields

“Functions & Scope” in Information Technology

65 questions across 2 technologies.

Information Technology

65 questions in 2 technologies

#QuestionTechnologyTopicLevel
1What is variable scope in PHP, and why can't a function normally access a variable defined outside of it? PHP › Functions & ScopePHPFunctions & ScopeBeginner
2How does recursion work in PHP functions, and what are the practical considerations, such as stack depth limits, when writing a recursive function? PHP › Functions & ScopePHPFunctions & ScopeAdvanced
3What does it mean that functions are 'first-class objects' in Python? Python › Functions & ScopePythonFunctions & ScopeBeginner
4What is Python's LEGB rule for variable scope resolution, and what does each letter stand for? Python › Functions & ScopePythonFunctions & ScopeIntermediate
5How does the 'nonlocal' keyword let a nested function modify a variable in its ENCLOSING (not global) scope? Python › Functions & ScopePythonFunctions & ScopeIntermediate
6What are default parameter values and variadic functions in PHP, and how do they add flexibility to how a function can be called? PHP › Functions & ScopePHPFunctions & ScopeIntermediate
7How does a closure capture variables from its enclosing scope, and what pitfall occurs when creating multiple closures inside a loop? Python › Functions & ScopePythonFunctions & ScopeAdvanced
8How do you define and call a basic function in PHP, and what are function parameters and return values? PHP › Functions & ScopePHPFunctions & ScopeBeginner
9What is the difference between positional arguments and keyword arguments when calling a function? Python › Functions & ScopePythonFunctions & ScopeBeginner
10How do default parameter values work, and when are they evaluated? Python › Functions & ScopePythonFunctions & ScopeBeginner
11Why do you need the 'global' keyword to MODIFY a global variable from inside a function, but not to simply READ it? Python › Functions & ScopePythonFunctions & ScopeIntermediate
12How do *args and **kwargs let a function accept an arbitrary number of positional and keyword arguments? Python › Functions & ScopePythonFunctions & ScopeIntermediate
13What are named arguments introduced in PHP 8, and how do they improve the readability of function calls with many parameters? PHP › Functions & ScopePHPFunctions & ScopeIntermediate
14How does the static keyword affect a variable declared inside a function, and how does this differ from a regular local variable? PHP › Functions & ScopePHPFunctions & ScopeIntermediate
15Why is using a mutable default argument (like an empty list) a classic Python bug, and how do you avoid it? Python › Functions & ScopePythonFunctions & ScopeAdvanced
16How do keyword-only arguments (using a bare '*' in the parameter list) force certain parameters to be passed by name only? Python › Functions & ScopePythonFunctions & ScopeAdvanced
17How do positional-only parameters (using a bare '/' in the parameter list, Python 3.8+) restrict how certain parameters can be passed? Python › Functions & ScopePythonFunctions & ScopeAdvanced
18How do you use functools.partial to create a new function with some arguments pre-filled? Python › Functions & ScopePythonFunctions & ScopeAdvanced
19How does Python evaluate default argument expressions ONLY ONCE at definition time, and what SAFE pattern exploits this for genuinely useful caching? Python › Functions & ScopePythonFunctions & ScopeAdvanced
20How do you correctly type-hint a function using *args and **kwargs with modern typing, like ParamSpec for preserving a wrapped function's exact signature? Python › Functions & ScopePythonFunctions & ScopeAdvanced
21How would you implement a function that dynamically inspects its own call arguments at runtime using the 'inspect' module, useful for building generic validation or logging decorators? Python › Functions & ScopePythonFunctions & ScopeAdvanced
22How do function type declarations and return type declarations improve code reliability, and how does PHP handle nullable and union types in function signatures? PHP › Functions & ScopePHPFunctions & ScopeAdvanced
23What is an anonymous function in PHP, and how does it differ from a regular named function? PHP › Closures & Anonymous FunctionsPHPClosures & Anonymous FunctionsBeginner
24What is the use keyword in a PHP closure, and why is it needed to access outside variables from within an anonymous function? PHP › Closures & Anonymous FunctionsPHPClosures & Anonymous FunctionsBeginner
25What is the difference between single quoted and double quoted strings in PHP, particularly regarding variable interpolation and escape sequences? PHP › Strings & String FunctionsPHPStrings & String FunctionsBeginner
26How does passing a variable by reference into a closure's use clause differ from the default pass by value behavior? PHP › Closures & Anonymous FunctionsPHPClosures & Anonymous FunctionsIntermediate
27How do you sort arrays in PHP, and what is the difference between functions like sort, asort, and usort? PHP › Arrays in PHPPHPArrays in PHPIntermediate
28How do variable variables and variable scope work in PHP, and what are common pitfalls to avoid? PHP › Basics & TypesPHPBasics & TypesIntermediate
29How do you create a basic command-line argument parser using argparse? Python › Command-Line Interfaces (argparse)PythonCommand-Line Interfaces (argparse)Beginner
30How do you create and run a basic thread using the threading module? Python › Concurrency (asyncio/threading/multiprocessing)PythonConcurrency (asyncio/threading/multiprocessing)Beginner
31What is the difference between a Python list and a tuple? Python › Data Types & StructuresPythonData Types & StructuresBeginner
32How do you use print statements effectively for debugging, including showing variable names alongside values? Python › Debugging & ProfilingPythonDebugging & ProfilingBeginner
33What is a decorator, and how does the @decorator_name syntax relate to a plain function call? Python › DecoratorsPythonDecoratorsBeginner
34How do you write a basic decorator that adds a print statement before and after calling the decorated function? Python › DecoratorsPythonDecoratorsBeginner
35What is an array in PHP and what types of arrays does PHP support? PHP › Arrays in PHPPHPArrays in PHPBeginner
36How do you add, remove, and access elements within a PHP array? PHP › Arrays in PHPPHPArrays in PHPBeginner
37What is the nullsafe operator introduced in PHP 8, and how does it simplify safely accessing a chain of potentially null properties or methods? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Beginner
38How do you run a PHP script from the command line, and how does this differ from running PHP through a web server? PHP › PHP CLI ScriptingPHPPHP CLI ScriptingBeginner
39How do you access command line arguments passed to a PHP script using the $argv and $argc superglobals? PHP › PHP CLI ScriptingPHPPHP CLI ScriptingBeginner
40What are type declarations in PHP, and how do they let you specify what kind of value a function parameter or return value should be? PHP › Type Declarations & Strict TypesPHPType Declarations & Strict TypesBeginner
41What is PHPUnit, and what is a unit test meant to actually verify about a piece of code? PHP › Unit Testing with PHPUnitPHPUnit Testing with PHPUnitBeginner
42How do you implement boolean flags using action='store_true' and action='store_false'? Python › Command-Line Interfaces (argparse)PythonCommand-Line Interfaces (argparse)Intermediate
43How do you send a value INTO a generator using the .send() method, and how does this differ from just calling next()? Python › Comprehensions & GeneratorsPythonComprehensions & GeneratorsIntermediate
44Why can't you use a mutable default value (like an empty list) directly as a dataclass field default, and how do you use field(default_factory=...) to fix it? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesIntermediate
45How does functools.partial work and when is it useful? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsIntermediate
46How do mutable default arguments create a subtle memory and correctness pitfall related to object lifetime? Python › Memory Management & Garbage CollectionPythonMemory Management & Garbage CollectionIntermediate
47What is the difference between an absolute import and a relative import within a package? Python › Modules & PackagingPythonModules & PackagingIntermediate
48What is __all__ and how does it control `from module import *` behavior? Python › Modules & PackagingPythonModules & PackagingIntermediate
49How does super() work in the context of multiple inheritance, and why is it more than just 'call the parent class'? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROIntermediate
50How do array_map, array_filter, and array_reduce help you transform and process array data without writing manual loops? PHP › Arrays in PHPPHPArrays in PHPIntermediate
51What is array destructuring in PHP, and how does the list function or short array syntax simplify extracting values from an array? PHP › Arrays in PHPPHPArrays in PHPIntermediate
52What are PHP's comparison operators, and how does the spaceship operator introduced in PHP 7 simplify writing custom comparison logic? PHP › Basics & TypesPHPBasics & TypesIntermediate
53What is the difference between a static property or method and an instance property or method in PHP? PHP › OOPPHPOOPIntermediate
54How do trait properties and static properties behave when a trait is used by multiple different classes, and is that state actually shared between them? PHP › TraitsPHPTraitsIntermediate
55What is the arrange act assert pattern, and how does structuring a test around these three distinct steps make tests clearer and easier to understand? PHP › Unit Testing with PHPUnitPHPUnit Testing with PHPUnitIntermediate
56How do you implement subcommands (like 'git commit' or 'git push') using argparse's add_subparsers()? Python › Command-Line Interfaces (argparse)PythonCommand-Line Interfaces (argparse)Advanced
57How would you use Python 3.10+'s kw_only=True (or per-field kw_only) to require dataclass fields be passed as keyword arguments only? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
58How do you stack MULTIPLE decorators on the same function, and in what order do they actually execute? Python › DecoratorsPythonDecoratorsAdvanced
59How does Python resolve circular imports, and what strategies avoid the resulting ImportError? Python › Modules & PackagingPythonModules & PackagingAdvanced
60How does the module search and caching system handle submodule imports like `import package.subpackage.module`? Python › Modules & PackagingPythonModules & PackagingAdvanced
61How does cooperative multiple inheritance require every class in the hierarchy to call super() consistently, even in __init__? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROAdvanced
62How would you design a mixin to be safely combinable with any base class's __init__ signature using **kwargs? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROAdvanced
63How does PHP handle array copying behavior, and when do arrays actually get passed by reference instead of by value? PHP › Arrays in PHPPHPArrays in PHPAdvanced
64How do data providers in PHPUnit let you run the exact same test logic repeatedly against many different sets of input data, without duplicating the test method itself? PHP › Unit Testing with PHPUnitPHPUnit Testing with PHPUnitAdvanced
65How does test driven development, commonly abbreviated as TDD, change the typical order in which tests and actual implementation code are written, and what benefits does this workflow claim to offer? PHP › Unit Testing with PHPUnitPHPUnit Testing with PHPUnitAdvanced