AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 166 of 840

What is the difference between Cython and CPython?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 9K+ Views

Python has multiple implementations, with CPython being the default interpreter and Cython being a superset language that compiles to C. Understanding their differences helps choose the right tool for your project. What is CPython? CPython is the reference implementation of Python written in C. It's the standard Python interpreter that most developers use daily. CPython interprets Python code at runtime, converting it to bytecode and then executing it on the Python Virtual Machine. Example A simple Python program running on CPython − def fibonacci(n): if n

Read More

What is calendar module in python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 4K+ Views

The calendar module in Python provides functions to display calendars and perform calendar-related operations. By default, these calendars have Monday as the first day of the week and Sunday as the last. Display the Calendar of an Year To display the calendar of an year, use the calendar() method and set year as the parameter − import calendar # Set the year year = 2022 # Display the calendar print(calendar.calendar(year)) The output of the above code is − ...

Read More

Python program to Find the first non-repeating character from a stream of characters?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 9K+ Views

In this article, we will find the first non-repeating character from a stream of characters. A non-repeating character is one that appears exactly once in the string. Let's say the following is our input ? thisisit The following should be our output displaying first non-repeating character ? h Using While Loop We will find the first non-repeating character by comparing each character with others using a while loop. This approach removes all occurrences of each character and checks if only one was removed ? # String my_str = "thisisit" ...

Read More

Print Single and Multiple variable in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 28K+ Views

To display single and multiple variables in Python, use the print() function. For multiple variables, separate them with commas or use formatting methods. Variables are reserved memory locations to store values. When you create a variable, you reserve space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Print Single Variable in Python To display a single variable, pass it directly to the print() function ? Example # Printing single values print(5) print(10) # Printing variables name = ...

Read More

Swap two variables in one line in using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

Python provides several ways to swap two variables in a single line. The most Pythonic approach uses tuple unpacking, but you can also use arithmetic or bitwise operators ? Using Tuple Unpacking (Recommended) Python's tuple unpacking allows you to swap variables in one elegant line using the comma operator ? a = 5 b = 10 print("Before swapping:") print("a =", a) print("b =", b) # Swap two variables in one line using tuple unpacking a, b = b, a print("After swapping:") print("a =", a) print("b =", b) Before swapping: a ...

Read More

Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 623 Views

In this example, we will count negative numbers in a column-wise and row-wise sorted matrix. A sorted matrix has elements arranged in ascending order both horizontally (across rows) and vertically (down columns). Understanding the Problem For a sorted matrix, once we encounter a positive number in a row, all subsequent elements in that row will also be positive. This property allows us to optimize our counting approach. Creating the Matrix Let's start by creating a sample sorted matrix ? matrix = [ [-7, -3, 2, 3], ...

Read More

How to input multiple values from user in one line in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 6K+ Views

In Python, to get multiple values from users in a single line, there are several approaches. The most common methods use split() with map() or list comprehension to parse space-separated input. Using Multiple input() Calls The basic approach uses separate input() calls for each value − x, y, z = input(), input(), input() print(x) print(y) print(z) If the user enters 5, 10, 15 in separate prompts, the output will be − 5 10 15 This method requires multiple user inputs, which is not ideal for single-line input. Using map() ...

Read More

How to write an empty function in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

In this article, we will see how we can create empty functions in Python. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Function blocks begin with the keyword def followed by the function name and parentheses (). Here, we will see examples of empty functions using the pass statement. What is the pass Statement? The pass statement is a null operation in Python. It does nothing when executed and serves as a placeholder ...

Read More

Reloading modules in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 20K+ Views

The reload() function is used to reload a previously imported module. This is particularly useful during interactive development sessions where you modify a module's code and want to see changes without restarting the Python interpreter. When you modify a module file after importing it, Python continues to use the cached version. The reload() function forces Python to re-read and re-execute the module code. How reload() Works When reload() is executed, several important things happen: The module's code is recompiled and re-executed, creating new objects bound to names in the module's dictionary Old objects are only ...

Read More

Difference between various Implementations of Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 459 Views

Python is a language specification that can be implemented in different ways. Most developers use Python without knowing which specific implementation runs on their system. When we say "Python, " we could mean CPython (the standard implementation), Jython, IronPython, PyPy, or other variants. Each implementation serves different purposes and has unique characteristics. Understanding these differences helps you choose the right Python implementation for your specific use case. CPython CPython is the reference implementation of Python written in C. It's the most widely used Python implementation and what most people simply call "Python." Key Features ...

Read More
Showing 1651–1660 of 8,392 articles
« Prev 1 164 165 166 167 168 840 Next »
Advertisements