Convert Camel Case to Snake Case in Python

Sarika Singh
Updated on 15-May-2025 12:58:38

4K+ Views

Camel case and snake case are ways of writing words together when we are programming. In camel case, we write words together without spaces and we start each new word with a capital letter except for the first word. For example, if we want to write a variable name for someone's date of birth, we can write it like this: dateOfBirth. In snake case, we write words together with an underscore symbol between them, and all the letters are lowercase. For example, if we want to write a variable name for someone's home address, we can write it like this: ... Read More

Pass Arguments by Value in Python Function

Sarika Singh
Updated on 15-May-2025 12:56:41

737 Views

In Python, when you pass arguments to a function, they are passed by object reference. This means the function gets a reference (or pointer) to the actual object, not a copy of it. However, how this reference affects the object depends on whether the object is mutable or immutable. Mutable objects (like lists, dictionaries, and sets) can be changed inside the function. If you modify a mutable object inside the function, the changes will affect the original object outside the function as well. Immutable objects (like numbers, strings, and tuples) cannot be changed. If you try to modify ... Read More

Pass Optional Parameters to a Function in Python

Sarika Singh
Updated on 15-May-2025 12:55:05

52K+ Views

In Python, you can pass optional parameters to functions, allowing you to call a function with fewer arguments than specified. Optional parameters are useful for providing default values when certain arguments are not provided. Python provides different ways to define optional parameters, including default values, variable-length argument lists, and keyword arguments. Using Default Arguments One common way to pass optional parameters is by setting default values for the parameters in the function definition. If no argument is passed for those parameters during the function call, the default value is used. Example In the following example, the greet() function has an ... Read More

Use Variable-Length Arguments in a Function in Python

Sarika Singh
Updated on 15-May-2025 12:51:57

20K+ Views

As the name implies, an argument with a variable length can take on a variety of values. You define a variable argument using a '*', for example *args, to show that the function can take a variable number of arguments. Observations on Python's variable-length arguments are as follows - The designation "*args" for variable length arguments is not required. The only thing needed is *; the variable name can be anything, like *names or *numbers. You can send zero or more arguments to a function using a variable length argument. ... Read More

Difference Between Attributes and Properties in Python

Sarika Singh
Updated on 15-May-2025 12:50:18

7K+ Views

In Python, everything is an object. And every object has attributes and methods, or functions. Attributes are described by data variables, for example like name, age, height, etc.Properties  Properties are a special kind of attributes that have getter, setter, and delete methods like __get__, __set__, and __delete__ methods. A property decorator in Python provides getter/setter access to an attribute. You can define getters, setters, and delete methods with the property function. If you just want the read property, there is also a @property decorator you can add above your method. Example This example shows how to use the @property decorator ... Read More

Produce Documentation for Python Functions

Sarika Singh
Updated on 15-May-2025 12:44:11

610 Views

In Python, documenting your functions is an important step that helps others understand what your code does, what inputs it expects, and what it returns. Python provides a built-in way to write documentation using docstrings. By producing good documentation, you can make your code more readable and usable in larger projects or by external users. Using Docstrings A docstring is a string that appears just after the definition of a function. It describes what the function does, its parameters, and its return value. You write it using triple quotes (""" or '''). Syntax Following is the syntax for writing a ... Read More

Difference Between Static and Final in Java

Alshifa Hasnain
Updated on 15-May-2025 11:26:06

17K+ Views

In this article, we will learn about the difference between static and final keywords in Java. Two of the most frequently used and frequently confused keywords are static and final. Although they may at times be used together in code, they have basically different functions. Static The static keyword can be applied to nested static classes, variables, methods, and blocks. It is not required to initialize the static variable when it is declared. This variable can be re-initialized. It can access the static members of the class only, and it can be called only by other static methods. Objects of ... Read More

Detect Mouse Movement Over Any Component in Java

Alshifa Hasnain
Updated on 15-May-2025 11:25:55

4K+ Views

In this article, we will learn to detect an event when the mouse moves over any component in Java. While building applications with Swing, detecting when the mouse enters or exits a component enables you to create responsive UIs with visual feedback. MouseListener We can implement a MouseListener interface when the mouse is stable while handling the mouse event. A MouseEvent is fired when we can press, release, or click (press followed by release) a mouse button (left or right button) at the source object or position the mouse pointer at (enter) and away (exit) from the source object. ... Read More

Set Foreground and Background Color to JComboBox Items in Java

Alshifa Hasnain
Updated on 15-May-2025 11:25:42

2K+ Views

In this article, we will learn set the foreground and background color to JComboBox items in Java. Setting basic foreground and background colors for the combo box helps to create interactive Swing-based applications. JComboBox A JComboBox is a subclass of the JComponent class, and it is a combination of a text field and a drop-down list from which the user can choose a value. A JComboBox can generate the ActionListener, ChangeListener, and ItemListener interfaces when the user actions with a combo box. setForeground() Method The setForeground() method can be used to set the foreground color of JComboBox items in ... Read More

Disable Cell Editing in JTable in Java

Alshifa Hasnain
Updated on 15-May-2025 11:25:24

5K+ Views

When working with JTables in Java Swing, there are many cases where one might need to display data that shouldn't be modified by users. In this article, we will learn to disable the cell editing inside a JTable in Java. JTable A JTable is a subclass of JComponent for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern to display the data in rows and columns. A JTable can fire TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener, and RowSorterListener interfaces. editCellAt() Method The editCellAt() method is used to prevent the JTable from editing a particular ... Read More

Advertisements