Found 10784 Articles for Python

Python GNU readline Interface

Chandu yadav
Updated on 30-Jul-2019 22:30:23

620 Views

The readline is UNIX specific module. It defines a number of functions to read and write history files in easier way from python interpreter. We can use this module directly or using the rlcompleter module. This module settings may affect the built-in input() method prompt and also the interactive prompt. For the MAC based system (on MAC OS X) this readline module can be implemented using the libedit library. The libedit configuration is different from GNU readline. To use this module, we need to import the readline module in the python code import readline Some methods of ... Read More

Python Internet String Preparation

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

235 Views

To identify different things in the internet, it is necessary to compare different identification for equality. The comparison procedure depends on the application domain. For an example, some things are case-insensitive etc. To check these kind of information stringprep is used. The RFC 3454 defines the procedure to prepare the Unicode strings before transmitting through the wire. After going through the preparation procedure, they have a certain normalized form. The RFC defines a set of tables; these tables can be combined into profiles. For an example there is a profile of stringprep is nameprep. In the nameprep, there are internationalized ... Read More

Python Unicode Database

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

328 Views

The unicodedata module is used to access all of the Unicode characters using Unicode character databases. In this database, there are character properties of all characters. To use this modules, we need to import the unicodedata module in our code. import unicodedata Unicode Database Methods Some modules of the unicodedata module are described here. Module (unicodedata.lookup(name)) − This method is used to lookup the characters by name. When the name is valid, it should return the character. Otherwise it will raise the KeyError. Module (unicodedata.name(chr[, default]))− This method is used to return the name of the given ... Read More

Python Text Wrapping and Filling

George John
Updated on 30-Jul-2019 22:30:23

5K+ Views

In python the textwrap module is used to format and wrap plain texts. There are some options to format the texts by adjusting the line breaks in the input paragraph. To use these modules, we need to import the textwrap module in our code. import textwrap The Textwrapper instance attributes of the constructors are as follows − Sr.No. Attribute & Description 1 width The maximum length of lines. Default value is 70 2 expand_tabs If the value of this attribute is true, then all tabs will be replaced by spaces. Default value ... Read More

String Operations in Python

Chandu yadav
Updated on 25-Jun-2020 13:48:21

618 Views

In python, there is a standard library, called string. In the string module, there are different string related constants, methods, classes are available.To use these modules, we need to import the string module in our code.import stringSome string constants and their corresponding values are as follows −Sr.No.String Constant & Values into it1string.ascii_lowercase‘abcdefghijklmnopqrstuvwxyz’2string.ascii_uppercase‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’3string.ascii_lettersConcatenation of asci_lowwecase and ascii_uppercase ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’4string.digits‘0123456789’5string.hexdigits‘0123456789abcdefABCDEF’6string.octdigits‘01234567’7string.punctuation‘!"#$%&\'()*+, -./:;?@[\]^_`{|}~’8string.printableAll printable ASCII characters. It is collection of asci_letters, punctuation, digits and whitespace.‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+, -./:;?@[\]^_`{|}~ \t\r\x0b\x0c’9string.whitespace‘\t\r\x0b\x0c’Example Code Live Demoimport string print(string.hexdigits) print(string.ascii_uppercase) print(string.printable)Output0123456789abcdefABCDEF ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+, -./:;?@[\]^_`{|}~String FormattingThe built-in string class in python supports different complex variable substitution and value formatting by the format() method.To format ... Read More

Concrete Exceptions in Python

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

2K+ Views

There are some common exceptions in python. These exceptions are usually raised in different programs. These may raise by the programmer explicitly, or the python interpreter can raise these type of exceptions implicitly. Some of these exceptions are − Exception AssertionError The AssertionError may raise, when an assert statement fails. In python there are some, we can also set some assert statement in our code. The assert statement always must be true. if the condition fails, it will raise AssertionError. Example Code class MyClass: def __init__(self, x): self.x = ... Read More

Python Exception Base Classes

Ankith Reddy
Updated on 25-Jun-2020 13:51:15

5K+ Views

Like other high-level languages, there are some exceptions in python also. When a problem occurs, it raises an exception. There are different kind of exceptions like ZeroDivisionError, AssertionError etc. All exception classes are derived from the BaseException class.The code can run built in exceptions, or we can also raise these exceptions in the code. User can derive their own exception from the Exception class, or from any other child class of Exception class.The BaseException is the base class of all other exceptions. User defined classes cannot be directly derived from this class, to derive user defied class, we need to ... Read More

Python Context Manager Types

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

245 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 Mapping Types

George John
Updated on 30-Jul-2019 22:30:23

12K+ Views

The mapping objects are used to map hash table values to arbitrary objects. In python there is mapping type called dictionary. It is mutable. The keys of the dictionary are arbitrary. As the value, we can use different kind of elements like lists, integers or any other mutable type objects. Some dictionary related methods and operations are − Method len(d) The len() method returns the number of elements in the dictionary. Operation d[k] It will return the item of d with the key ‘k’. It may raise KeyError if the key is not mapped. Method iter(d) This method will ... Read More

Python Set Types

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

3K+ Views

The sets are basically an unordered collection of distinct hash-table objects. We can use the set for some mathematical operations like set union, intersection, difference etc. We can also use set to remove duplicates from a collection. The set do not record the element position. It does not support the indexing, slicing or other sequence related operations. In python there are basically two types of sets. The set and the frozenset. The set type is mutable, whether the frozenset is immutable. We can perform add(), remove() and these kind of operations on set, but it is not possible for frozenset. ... Read More

Advertisements