Programming Articles

Page 577 of 2547

Variable-length arguments in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 6K+ Views

You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition, unlike required and default arguments. Syntax Syntax for a function with non-keyword variable arguments is this − def functionname([formal_args, ] *var_args_tuple): "function_docstring" function_suite return [expression] An asterisk (*) is placed before the variable name that holds the values of all nonkeyword variable arguments. This tuple remains empty if no additional arguments ...

Read More

Required arguments in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 9K+ Views

Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition. To call the function printme(), you definitely need to pass one argument, otherwise it gives a syntax error as follows ? Example with Missing Required Argument # Function definition is here def printme(str): "This prints a passed string into this function" print(str) return # Now you can call printme function printme() When ...

Read More

Pass by reference vs value in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 12K+ Views

In Python Call by Value and Call by Reference are two types of generic methods to pass parameters to a function. In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can be changed. Call by Value in Python When we pass an argument to a function, it is stored locally (in the stack memory), i.e the scope of these variables lies within the function and these will not affect the values of the global variables (variables outside function). In Python, "passing by value" is possible only with the immutable types ...

Read More

Calling a Function in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 588 Views

Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme() function ? Example # Function definition is here def printme(str): """This prints a passed string into this function""" print(str) return # Now you can call printme ...

Read More

Autorun a Python script on windows startup?

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Making a Python script run automatically when Windows starts can be useful for background tasks, monitoring applications, or system utilities. There are two main approaches: using the Startup folder or modifying the Windows Registry. Method 1: Using Windows Startup Folder The simplest approach is to place your Python script (or a shortcut to it) in the Windows Startup folder. Windows automatically runs all programs in this folder during boot. Startup Folder Location C:\Users\current_user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ Steps to Add Script 1. Navigate to the Startup folder (you may need to enable "Show hidden files" ...

Read More

Built-in Dictionary Functions & Methods in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 14K+ Views

Python dictionaries come with built-in functions and methods that make working with key-value pairs efficient and straightforward. These functions help you manipulate, query, and transform dictionary data. Built-in Dictionary Functions Python provides several built-in functions that work with dictionaries ? len() Function student = {'name': 'Alice', 'age': 20, 'grade': 'A'} print(len(student)) 3 str() Function student = {'name': 'Alice', 'age': 20} print(str(student)) print(type(str(student))) {'name': 'Alice', 'age': 20} type() Function student = {'name': 'Alice', 'age': 20} print(type(student)) ...

Read More

Properties of Dictionary Keys in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 5K+ Views

Dictionary values have no restrictions. They can be any arbitrary Python object, either standard objects or user-defined objects. However, the same is not true for dictionary keys. There are two important points to remember about dictionary keys: No Duplicate Keys Allowed More than one entry per key is not allowed. When duplicate keys are encountered during assignment, the last assignment wins ? # Duplicate keys - last value overwrites previous ones student = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'} print("student['Name']:", student['Name']) print("Full dictionary:", student) student['Name']: Manni Full dictionary: {'Name': 'Manni', 'Age': 7} ...

Read More

Built-in Tuple Functions in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 10K+ Views

Python provides several built-in functions to work with tuples. These functions help you perform common operations like finding length, maximum/minimum values, and converting sequences to tuples. len() Function The len() function returns the total number of elements in a tuple ? numbers = (1, 2, 3, 4, 5) fruits = ('apple', 'banana', 'orange') empty_tuple = () print("Length of numbers:", len(numbers)) print("Length of fruits:", len(fruits)) print("Length of empty tuple:", len(empty_tuple)) Length of numbers: 5 Length of fruits: 3 Length of empty tuple: 0 max() Function The max() function returns the ...

Read More

No Enclosing Delimiters in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 347 Views

In Python, when you write multiple objects separated by commas without any enclosing delimiters (like brackets [] for lists or parentheses () for tuples), Python automatically treats them as tuples. This behavior is called implicit tuple creation. Basic Tuple Creation Without Delimiters Here's how Python interprets comma-separated values without delimiters ? # Multiple values without delimiters create a tuple data = 'abc', -4.24e93, 18+6.6j, 'xyz' print(data) print(type(data)) ('abc', -4.24e+93, (18+6.6j), 'xyz') Tuple Unpacking This implicit tuple creation is commonly used with tuple unpacking ? # Tuple unpacking ...

Read More

Basic Tuples Operations in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 561 Views

Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string. In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter − Basic Tuple Operations Python Expression Results Description ...

Read More
Showing 5761–5770 of 25,466 articles
« Prev 1 575 576 577 578 579 2547 Next »
Advertisements