Found 10784 Articles for Python

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

576 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

270 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

Python Truth Value Testing

AmitDiwan
Updated on 12-Aug-2022 12:54:26

901 Views

What is Truth Value We can use any object to test the truth value. By providing the condition in the if or while statement, the checking can be done. Until a class method __bool__() returns False or __len__() method returns 0, we can consider the truth value of that object is True. The value of a constant is False, when it is False, or None. When a variable contains different values like 0, 0.0, Fraction(0, 1), Decimal(0), 0j, then it signifies the False Value. The empty sequence ‘‘, [], (), {}, set(0), range(0), Truth value of these elements are ... Read More

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

AmitDiwan
Updated on 11-Aug-2022 10:03:48

869 Views

In this article, we will remove the nth character from a string in Python. Let’s say we have the following input string − Amitdiwan The output should be the following after removing nth character i.e. 2nd index − Amt Python program for removing n-th character from a string In this example, we will remove the nth character from a string − Example def removechar(str1, n): x = str1[ : n] y = str1[n + 1: ] return x + y # Driver Code if __name__ == '__main__': str1 = input("Enter a String =") n = int(input("Enter the ... Read More

Python program to print check board pattern of n*n using numpy

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

846 Views

Given the value of n, our task is to display the check board pattern for a n x n matrix. Different types of functions to create arrays with initial value are available in numpy . NumPy is the fundamental package for scientific computing in Python. Algorithm Step 1: input order of the matrix. Step 2: create n*n matrix using zeros((n, n), dtype=int). Step 3: fill with 1 the alternate rows and columns using the slicing technique. Step 4: print the matrix. Example Code import numpy as np def checkboardpattern(n): print("Checkerboard pattern:") ... Read More

Prefix sum array in python using accumulate function

karthikeya Boyini
Updated on 25-Jun-2020 11:31:53

382 Views

Given an array and we have to do the prefix sum array using accumulate function.itertools.accumulate(iterable[, func]) module functions all construct and return iterators. So they should only be accessed by functions or loops that truncate the stream. Make an iterator that returns accumulated sums. Elements may be any addable type including Decimal or Fraction. If the optional function argument is supplied, it should be a function of two arguments and it will be used instead of addition.ExampleInput Data = [1, 0, 2, 3, 5] >>> list(accumulate(data)) # running summation Output [1, 1, 3, 6, 11]AlgorithmStep 1: Create list. Step 2: ... Read More

Python program using map function to find row with maximum number of 1's

AmitDiwan
Updated on 11-Aug-2022 09:03:32

213 Views

In this article, we will learn how to use map function to find row with maximum number of 1's. 2D array is given and the elements of the arrays are 0 and 1. All rows are sorted. We have to find row with maximum number of 1's. Here we use map (). The map function is the simplest one among Python built-ins used for functional programming. These tools apply functions to sequences and other iterables. Let’s say the input is the following array − [[0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, ... Read More

Advertisements