
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

991 Views
In Python, a Dictionary is one of the data structures that contains key-value pairs enclosed in curly braces '{}'. It is a Mutable and unordered data structure. Before proceeding with adding new keys to a dictionary, first let's create a dictionary with key and values. Following is the example of creating a dictionary with specified key and values - dict1 = {'key1': 'Tutorials', 'key2': 'Point', 'key3': 'Python'} print("Created Dictionary:", dict1) Following is the output of the above example - Created Dictionary: {'key1': 'Tutorials', 'key2': 'Point', 'key3': 'Python'} Adding new keys to a Dictionary Once a Dictionary is ... Read More

248 Views
In Python, a Dictionary is a unordered and muttable data structure which stores data as a key-value pair. In some cases, we may need to merge two dictionaries into a single dictionary by using a single expression, in such scenarios python provides different methods. Using | Merge Operator The | merge operator in Python is used to merge multiple dictionaries into one with a single expression and returns the combined dictionary as a new dictionary. If both dictionaries have the same key, then the value from the dictionary on the right side of the operator will be replaced with the ... Read More

255 Views
In Python, converting different data types into strings is a common requirement when we want to display or store information in text format. The built-in str() function is used for this conversion. This function accepts any Python object as a parameter and returns a string representation of it. The basic syntax of the str() function is as follows: str(object) Where object is any valid Python object, such as int, float, bool, list, etc. In this article, we will explore different data type conversions into a string in Python. Conversion of Integer to String An integer can be converted into ... Read More

865 Views
Data conversion in Python refers to changing the data type of a value to another data type. Python supports two different types of data conversion, such as Implicit conversion and explicit conversion. Implicit Conversion is performed by the Python interpreter automatically. Explicit Conversion is manually done by the programmer using built-in functions in Python Implicit Conversion Python automatically converts one data type to another, and this type of conversion is called Implicit conversion. To avoid any data loss during runtime, the smaller data type is converted ... Read More

477 Views
When working with strings, we may need to concatenate or join multiple strings together. Python provides several methods to perform the concatenation of strings. Following are various ways to print concatenated strings using a single statement. Using the "+" Operator Using f-string Using format() Method Using join() Method Using print() with Multiple Arguments Using List or Tuple Unpacking Using map() with str Using the "+" Operator The "+" operator is the simplest and most direct way to concatenate two or more strings in Python. It joins the strings end-to-end. Here's an example of using the + operator - ... Read More

274 Views
Printing a String Twice Using Multiplication When we are developing Python, we may want to repeat or duplicate a string for display or formatting purposes. In such cases, Python provides several ways to print a string in defined number of times with a single statement. There are different ways to print a string twice with a single statement in Python. They are - Using Multiplication Operator Using the Concatenation Operator Using the format() Method Using f-string Using join() ... Read More

381 Views
The following code splits given string by a period and a line break as followsExampleimport re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.]+', s) print resultOutputThis gives the following output['Hi', "It's nice meeting you", 'My name is Jason']

2K+ Views
In Python, the re module is used to work with regular expressions. In some cases, we need to check whether a string starts or ends with a specific pattern, and then we need to use special regex characters called anchors. Following are the anchors used in regular expressions - ^ − This anchor matches the beginning of a string. $ − This anchor matches the end of a string. Python Regex Methods The following methods from the re module are commonly used to apply start and end matching - ... Read More

4K+ Views
In Python, string comparisons are case-sensitive by default. For example, when we consider the strings "Hello" and "hello" then they are considered as two different strings because of the difference in their letter casing. Case-insensitive String Comparison in Python In some tasks, such as searching user input, comparing filenames, or processing natural language, it's important to compare strings without considering case differences. To perform string comparison in Python, we have several built-in methods such as lower(), upper(), and casefold(), which help us to normalize the casing of strings before comparing them. ... Read More

16K+ Views
File manipulation is a fundamental aspect of programming, especially when dealing with data processing and management. Python offers powerful tools for handling files and text efficiently. A common task is searching for specific text patterns within a file and replacing them with desired content. This article explores several practical methods for searching and replacing text in a file using Python. Basic Text Replacement Let's start with a simple example of searching for a specific word in a file and replacing it with another word. In this particular example, we'll search for the word "old" and replace it with "new" − ... Read More