My Blog

My WordPress Blog

My Blog

My WordPress Blog

Python

Add List Items

Add List Items Adding list items in Python implies inserting new elements into an existing list. Lists are mutable, meaning they can be modified after creation, allowing for the addition, removal, or modification of their elements. Adding items in a list typically refers to appending new elements to the end of the list, inserting them […]

 Lists

Python Lists List is one of the built-in data types in Python. A Python list is a sequence of comma separated items, enclosed in square brackets [ ]. The items in a Python list need not be of the same data type. Following are some examples of Python lists − List is an ordered collection […]

String Exercises

Example 1 Python program to find number of vowels in a given string. Open Compiler It will produce the following output − Example 2 Python program to convert a string with binary digits to integer. Open Compiler It will produce the following output − Change mystr to ’10, 101′ Example 3 Python program to drop all digits from a string. Open […]

String Methods

Python’s built-in str class defines different methods. They help in manipulating strings. Since string is an immutable object, these methods return a copy of the original string, performing the respective processing on it. The string methods can be classified in following categories − Case Conversion Methods This category of built-in methods of Python’s str class deal with the conversion […]

Escape Characters

Escape Character An escape character is a character followed by a backslash (\). It tells the Interpreter that this escape character (sequence) has a special meaning. For instance, \n is an escape sequence that represents a newline. When Python encounters this sequence in a string, it understands that it needs to start a new line. Unless an ‘r’ or […]

String Formatting

String formatting in Python is the process of building a string representation dynamically by inserting the value of numeric expressions in an already existing string. Python’s string concatenation operator doesn’t accept a non-string operand. Hence, Python offers following string formatting techniques − Using % operator The “%” (modulo) operator often referred to as the string formatting […]

 Modify Strings

String modification refers to the process of changing the characters of a string. If we talk about modifying a string in Python, what we are talking about is creating a new string that is a variation of the original one. In Python, a string (object of str class) is of immutable type. Here, immutable refers to an object that cannot be modified in […]

Scroll to top