Found 10400 Articles for Python

Python Context Manager Types

Chandu yadav
Updated on 25-Jun-2020 13:51:46

250 Views

In python, the runtime context is supported by the with statement. The context is defined by the context manager. Using the context manager, we can create user defined classes to define the runtime context. It enters into the task before executing the statement body, and when the statement body is completed, it ends.There are two different methods for context manager. These methods are −Method __enter__()The __enter__() method is used to enter into the runtime context. It will return either the current object or another related object. The returned value is bound to the identifier in as clause of the with ... Read More

Python Binary Sequence Types

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

4K+ Views

The byte and bytearrays are used to manipulate binary data in python. These bytes and bytearrys are supported by buffer protocol, named memoryview. The memoryview can access the memory of other binary object without copying the actual data. The byte literals can be formed by these options. b‘This is bytea with single quote’ b“Another set of bytes with double quotes” b‘’’Bytes using three single quotes’’’ or b“””Bytes using three double quotes””” Some of the methods related to byte and bytearrays are − Method fromhex(string) The fromhex() method returns byte object. It takes a string where each byte is ... Read More

Python Sequence Types

SaiKrishna Tavva
Updated on 18-Dec-2024 19:22:23

10K+ Views

In Python programming, some basic sequence type classes are, Lists , Strings , Tuples, Range, etc, these data structures hold an ordered collection of items. They allow us to access their elements through indexing and iteration, there are additional sequence-type objects such as Byte sequences. Sequence Types In Python Sequence types in Python are categorized into two types they are mutable and immutable sequences. Mutable Sequence Types These Sequences can be changed after their creation, and also we can modify elements, adding new elements and removing existing ones. Lists: A list is a mutable, ordered ... Read More

Python Numeric Types

AmitDiwan
Updated on 11-Aug-2022 11:00:28

4K+ Views

The Numeric Types in Python are the integer datatypes. It includes integers, floatimg point, complex, etc. The complex includes real and imag parts. Also, includes Hexadecimal and Octal types. Python int datatype The Numeric Types include the int datatypes − a = 5 print("Integer = ", a) print("Type = ", type(a)) Output Integer = 5 Type = Python float datatype The Numeric Types include the float datatypes − Example a = 7E2 print("Float = ", a) print("Type = ", type(a)) Output Float = 700.0 Type = Python complex datatype The Numeric Types include the ... Read More

Python program for removing n-th character from a string?

Akshitha Mote
Updated on 23-Jun-2025 19:30:06

1K+ Views

The problem statement is to remove the nth character from the given string. Let's understand with an example. Consider my_string = "Tutorialspoint". The given value of n is 6; then we need to remove the 5th character from the string. Because the index value starts from zero. And it should result in "Tutorialspoint". Removing nth Character using a for Loop The for loop can be used to remove the n-th character from a string. In this approach, we iterate through each index of the string and print the characters. If the index value is equal to the given (n-1)th value, we ... Read More

Python program to check for URL in a string

Sarika Singh
Updated on 04-Apr-2023 11:47:24

3K+ Views

This article will teach you how to determine whether a string contains a URL or not. In Python, strings are collections of bytes that represent Unicode characters. You can use single or double quotes and everything enclosed in them is considered as a string. When given a string, we will first determine whether it contains a URL. If one is found, we will then print the URL. Using findall() method We will employ Python's regular expression concept to resolve this issue. Regular expressions are supported by the Python re package. Using a particular syntax defined in a pattern, a regular ... Read More

Python Program to print unique values from a list

Sarika Singh
Updated on 23-Nov-2022 08:24:42

3K+ Views

List is a built-in data structure in python which functions like a dynamically sized array. Lists are created by putting elements in square brackets ‘[element 1, element 2, ….]’. Elements present in list are indexed and the indexing starts from [0]. List has the following properties − List is mutable meaning that elements can be added, removed or changed from a list after its creation. List is ordered, so adding new elements to the list will not change the order of existing elements. List allows for entry of duplicate elements since each element has a unique index. A single ... Read More

Python program to sort a tuple by its float element

Sarika Singh
Updated on 23-Nov-2022 07:33:43

2K+ Views

This article will demonstrate how write a Python program to sort a tuple (made up of float elements) using its float elements. Here, we'll look at both how to sort using the in-built sorted() function and how to sort using the in-place method of sorting. Input-Output Scenarios Following is an input and its output scenario determining the sorting of a tuple by its float element − Scenario-1 Input: tuple = [(‘Dengu’, ’54.865’), (‘Malaria’, ‘345.743’), (‘Corona’, ‘456.864’), (‘Typhoid’, ‘35.285’), (‘Jaundice’, ’83.367’)] Output: [(‘Corona’, ‘456.864’), (‘Malaria’, ‘345.743’), (‘Jaundice’, ’83.367’), (‘Dengu’, ’54.865’), (‘Typhoid’, ‘35.285’)] In the above scenario we can see that ... Read More

Python Program to find mirror characters in a string

Sarika Singh
Updated on 23-Nov-2022 07:25:19

3K+ Views

This article teaches you how to write a python program to find mirror characters in a string. Let us first understand what mirror characters in a string are. Two identical alphabetically positioned characters, one from the front and the other from the back, are known as mirror characters. For example, the alphabet a's mirror character is "z, " "b's" is "y, " and so on. Input-Output Scenario Following is an input and its output example of mirror characters in a string − Input: p = 3 Input string = Coding Output: Cowrmt Here, the alphabets “d”, “i”, “n”, “g” ... Read More

Calendar function in Python

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

1K+ Views

Python has an in built module called calendar which operation is related to calendar. There are some calendar functions in Python. calendar(year, w, l, c) This function shows the year, width of characters, no. of lines per week and column separations. Example print ("The calendar of 2014 is : ") print (calendar.calendar(2014, 3, 1, 4)) Output The calendar of year 2014 is : 2014 January ... Read More

Advertisements