Found 35163 Articles for Programming

Concrete Exceptions in Python

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

1K+ 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

4K+ 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

221 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

11K+ 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

Python Binary Sequence Types

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

3K+ 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 Text Sequence Types

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

521 Views

In python the str object, handles the text or string type data. Strings are immutable. The strings are sequence of Unicode characters. We can use single quote, double quotes or triple quotes to define the string literals. ‘This is a string with single quote’ “Another Text with double quotes” ‘’’Text using three single quotes’’’ or “””Text using three double quotes””” We can use triple quotes to assign multiline strings in python. There is different string related functions. Some of the String methods are as follows − Sr.No. Operation/Functions & Description 1 s.capitalize() Convert first ... Read More

Python Sequence Types

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

6K+ Views

Some basic sequence type classes in python are, list, tuple, range. There are some additional sequence type objects, these are binary data and text string. Some common operations for the sequence type object can work on both mutable and immutable sequences. Some of the operations are as follows − Sr.No. Operation/Functions & Description 1 x in seq True, when x is found in the sequence seq, otherwise False 2 x not in seq False, when x is found in the sequence seq, otherwise True 3 x + y Concatenate two sequences x ... Read More

Python Numeric Types

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

3K+ 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 Boolean Operations

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

256 Views

The basic Boolean operations are and, or, not operations. The and operation − The basic syntax of and operation is: x and y. It indicates that when the x is false, then return x, otherwise returns y. The or operation −The basic syntax of or operation is: x or y. It indicates that when the x is false, then return y, otherwise returns x. The not operation − The basic syntax of and operation is: not x. It indicates that when the x is false, then it returns true, otherwise it returns false. Example Code Live ... Read More

Advertisements