
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

19K+ Views
In Python, it is possible to execute the dynamically generated code or code stored as a string using the Python built-in functions like eval() and exec(). Both eval() and exec() functions should be used carefully, especially with untrusted input, as they execute any code, including the harmful instructions causing the security risk. In this article we will we go through several example of how to execute string containing the python code. Using Python eval() Function The Python eval() function is used to evaluate the string as a python expression and return ... Read More

17K+ Views
In Python, Functions are the first-class object, which means they can be passed around and manipulated like other data types (like integers, strings). This allows to inspect and retrieve the attribute of functions, including their names. In this article we are going to learn about getting the function names as string, To achieve we are going to use the built-in __name__ attribute. Let's dive into the article to learn more about it. Using Python Class __name__ Attribute The Python __name__ attribute is a special built-in variable that helps to determine the context in a which a Python ... Read More

1K+ Views
In Python, strings are immutable, which means once the string is created, it cannot be changed. Because of this immutability, any operation that tries to modify the string results in creating a new string object with a different identity. Every object in Python has a unique identity, which can be accessed by using the built-in id() function. In this article, we are going to learn about changing the id of an immutable string in Python. We cannot directly change the ID of the immutable string, but by reassigning or modifying it, we can create a new string and ... Read More

1K+ Views
You generate random strings with upper case letters and digits in Python. Here are three different ways to do it: Using random.choices() and string.ascii_uppercase In this method, we will use the random.choices() function to randomly choose characters from the string.ascii_uppercase and string.digits strings to generate a random string. Example We first import the random and string modules, which we will use to generate random characters and create strings, respectively. We define the length of the random string we want to generate (in this example, it's 10). We define the possible characters that can be used to create the random string, ... Read More

32K+ Views
In Python Variables are just the labels that are pointing to the values. They don't carry any built-in metadata about their names. That’s why there is no direct built-in method to get the variable name as a string. However, we can achieve this, by inspecting the environment such as using the globals(), locals(), or the inspect module. Let's dive into the article to learn more about getting a variable name as a string. Using Python globals() Function The Python globals() function is used to return a dictionary representing the current global symbol table. It provides ... Read More

48K+ Views
A Hexadecimal is the base-16 number system that uses the digits from the '0 to 9' and letters from 'A to F'. It is commonly used in the computers to represent the binary data in the readable format. In this article we are going to learn about converting hex string into int. For example, if we receive the input as a hex string("12xf2") and need to convert it into a integer. For achieving this, Python provides the multiple methods let's explore them one by one. Using Python int() Function The Python int() function is used to convert ... Read More

2K+ Views
When working with strings in Python, you might often find the need to remove specific characters. This could be driven by various needs such as data cleaning, formatting, or simply modifying text for output. Below are several methods to remove specific characters from a string. Using str.replace() Using a Loop Using str.translate() Using List Comprehension Using 'str.replace()' Method The simplest way to remove specific characters from a string is to use the str.replace() method. This method allows you to replace occurrences of ... Read More

13K+ Views
There are several ways to extract numbers from a string in Python. One way to extract numbers from a string is to use regular expressions. Regular expressions are patterns that you can use to match and manipulate strings. Here's an example code snippet that uses regular expressions to extract all the numbers from a string: Using the re.findall() function Example In this example, we're using the re.findall() function to search for all occurrences of numbers in the text string. The regular expression \d+\.\d+|\d+ matches both floating-point numbers and integers. import re text = "The price of the book is $29.99" ... Read More

648 Views
In Python, a substring is a sequence of characters that appears within a larger string. For example, in the string "Hello, world!", the substring "world" appears within the larger string. A substring can be a single character, or it can be a longer sequence of characters. Substrings are useful when you need to extract or manipulate specific parts of a string. You can also check if a substring is contained within a larger string using Python's string methods. Python provides a built-in method to check if a string contains a substring. The method is called ‘in’ and it returns a ... Read More

475 Views
To convert byte literals to Python strings, you need to decode the bytes. It can be done using the decode method on the bytes object. example>>> b"abcde".decode("utf-8") u'abcde'You can also map bytes to chr if the bytes represent ASCII encoding as follows −bytes = [112, 52, 52] print("".join(map(chr, bytes)))Outputp44