Gireesha Devara has Published 248 Articles

How can I convert a Python tuple to string?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 13:30:09

6K+ Views

A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. There are three different ways we can convert a python ... Read More

How can I iterate through two lists in parallel in Python?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 13:28:07

620 Views

In Python, using a for loop is common to iterate a single data structure like list, but what if we need to iterate two/multiple lists parallelly?. In this article we will see different ways to iterate two/multiple lists parallelly. By using range() function, we can iterate the two lists ... Read More

How to convert a String representation of a Dictionary to a dictionary in Python?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 13:24:45

6K+ Views

To convert a string represented dictionary to an original dictionary we can use built-in functions like eval(), json.load(), and ast.literal_eval(). Initially, we must ensure that the string contains a valid representation of the dictionary. Let’s discuss how each function will convert the string representation of a dictionary to an original ... Read More

How do I check what version of Python is running my script?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 13:17:21

425 Views

Python is being updated regularly with new features and supports. Starting from 1994 to current release, there are lots of updates in Python versions. By using Python standard libraries like sys or platform modules we can get the version information of Python that is actually running on our script. In ... Read More

How we can update a Python list element value?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 13:00:55

562 Views

In Python lists are one the built−in data structure which is used to store collections of data. The lists are mutable, which means we can modify its element after it is created. We have some list methods like append, insert, extend, remove, and clear which are used to change the ... Read More

How to create Python objects based on an XML file?

Gireesha Devara

Gireesha Devara

Updated on 24-Aug-2023 12:45:36

1K+ Views

XML (Extensible Markup Language), which is a markup−language that is used to structure, store, and transfer data between systems. At some point we need to read/write the XML data using the Python language. By using the untangle library we can create Python objects based on an XML file. The untangle ... Read More

Is there any Python object inspector?

Gireesha Devara

Gireesha Devara

Updated on 23-Aug-2023 19:09:55

273 Views

In python there is no built−in or normal function that acts as an object inspector. But we can use functions like type(), help(), dir(), vars() or modules like inspect are used to find the attributes, properties and methods of any object. Also we have other functions like id(), getattr(), ... Read More

How to break a for loop in Python?

Gireesha Devara

Gireesha Devara

Updated on 23-Aug-2023 19:08:22

2K+ Views

In Python normally for loops are constructed to iterate over a block for each item in a range. If a premature termination of loop is sought before all iterations are completed, then we can use break keyword. It is invariably used in a conditional statement inside the body of a ... Read More

How to prevent loops going into infinite mode in Python?

Gireesha Devara

Gireesha Devara

Updated on 23-Aug-2023 19:02:26

2K+ Views

In python the while loop needs to be controlled by making some provision inside the body of the loop to drive the condition mentioned in the beginning to false. This is usually done by keeping count of iterations. If the while loop condition never evaluates to False, then we will ... Read More

How to convert float to integer in Python?

Gireesha Devara

Gireesha Devara

Updated on 23-Aug-2023 18:42:17

1K+ Views

In python there are two number data types: integers and floats. In general integers do not have any decimal points and base value is 10 (i.e., Decimal). Whereas floats have decimal points. Python provides some built−in methods to convert floats to integers. In this article we will discuss some of ... Read More

Advertisements