Found 33676 Articles for Programming

How do we compare two tuples in Python?

Lakshmi Srinivas
Updated on 05-Mar-2020 05:57:34

6K+ Views

Tuples are compared position by position: the first item of the first tuple is compared to the first item of the second tuple; if they are not equal, this is the result of the comparison, else the second item is considered, then the third and so on. example>>> a = (1, 2, 3) >>> b = (1, 2, 5) >>> a < b TrueThere is another type of comparison that takes into account similar and different elements. This can be performed using sets. Sets will take the tuples and take only unique values. Then you can perform a & operation that ... Read More

How can I convert Python tuple to C array?

Vikram Chiluka
Updated on 14-Apr-2025 15:21:18

10K+ Views

In this article, we will show you how to convert a Python tuple to a C array. Python does not have a built-in array data type like other programming languages, but you can create an array using a library like Numpy. Tuple to Array Conversion Using Python The Python NumPy library provides various methods to create manipulate and modify arrays in Python Following are the two important methods that helps us to convert a tuple into an array − Using numpy.asarray() method Use numpy.array() method If you haven't already installed NumPy on your system, run the following ... Read More

Why python returns tuple in list instead of list in list?

SaiKrishna Tavva
Updated on 15-Apr-2025 12:23:49

494 Views

In Python, especially in situations like iterating through data structures, working with built-in functions, or fetching records from a database, lists of tuples are returned by the pre-defined functions instead of a list of lists. This is because tuples are immutable i.e., we cannot modify them after creation, whereas lists are mutable; once obtained, we can change their contents. This makes tuples ideal for storing fixed data like database records or function results, ensuring data integrity. Let us see methods/functions in Python that return a list of tuples - The enumerate() Function The enumerate() function is used to add a counter to ... Read More

How can I preserve Python tuples with JSON?

Samual Sam
Updated on 30-Jul-2019 22:30:22

408 Views

There is no concept of a tuple in the JSON format. Python's JSON module converts Python tuples to JSON lists because that's the closest thing in JSON to a tuple. Immutability will not be preserved. If you want to preserve them, use a utility like a pickle or write your own encoders and decoders.If you're using pickle, it won't store the Python temples in JSON files but in pkl files. This isn't useful if you're sending data across the web. The best way is to use your own encoders and decoders that will differentiate between lists and tuples depending on ... Read More

What is the homogeneous list in Python list?

Disha Verma
Updated on 20-May-2025 14:52:06

1K+ Views

In Python, a list is a mutable data type used to store a collection of items, which are separated by commas and enclosed within square brackets [ ]. According to the Python documentation, there is no concept of a homogeneous list in Python. However, a Python list can contain collections of homogeneous items, meaning that the data types of the items are the same. Python List of Homogeneous Data A Python list can contain both homogeneous and heterogeneous data. Example  Here is an example of a list containing homogeneous data - # List containing ... Read More

How can I convert bytes to a Python string?

Vikram Chiluka
Updated on 01-Sep-2025 14:48:51

11K+ Views

In this article, we will show you how to convert bytes into a string in Python. Strings are sequences of characters, while bytes are 8-bit values. To convert a sequence of characters to 8-bit values, we can utilize Python's built-in methods, which we will explore in this article. Converting Bytes to Strings in Python The following methods can be efficiently used to convert bytes to Python string. Using decode() function Using str() function Using codecs.decode() function Using pandas library ... Read More

Java is also not pure object-oriented like c++

Pythonista
Updated on 30-Jul-2019 22:30:22

417 Views

the main() method in Java code is itself inside a class. The static keyword lets the main() method which is the entry point of execution without making an object but you need to write a class. In C++, main() is outside the class and writing class it self is not mandatory. Hence, C++ is not a pure object oriented language bu Java is a completely object oriented language.

Multiple .java files

Mohammad Mohtashim
Updated on 30-Jul-2019 22:30:22

430 Views

You can use Advanced IDE to use multiple files. Here is the link:https://www.tutorialspoint.com/online_java_compiler.php

How to convert a string to a integer in C

Pythonista
Updated on 27-Jan-2020 12:41:27

643 Views

First extract characters from left bracket '(' using strchr() function.char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');Then add each character within brackets () to an char arraychar y[5]=""; int  p; for (p=1;p

How do we include the direction of text display in HTML?

Rishi Rathor
Updated on 24-Jun-2020 07:36:47

204 Views

Use the dir attribute in HTML, to add the direction of the text.ExampleYou can try to run the following code to include the direction of text display in HTML −           This is demo text from left-to-right.       This is demo text from right-to-left.    

Advertisements