Found 10805 Articles for Python

Inplace Operators in Python - ixor(), iand(), ipow()

Pavitra
Updated on 07-Aug-2019 07:27:12

159 Views

In this article, we will learn about some of the inplace operators available in Python 3.x. Or earlier.Python provides methods to perform inplace operations, i.e assignment and computation simultaneously using in a single statement with the help of “operator” module. Here we will discuss about ixor(), iand(), ipow() functions .ixor()This function allows us to assign and xor current value. This operation behaves like “a^=b” operation. Assigning can’t be performed in case of immutable data types, such as strings and tuples.Exampleimport operator as op # using ixor() to xor int1 = op.ixor(786, 12); # displaying value print ("The value ... Read More

Absolute and Relative frequency in Pandas

Pradeep Elance
Updated on 03-Jul-2020 07:45:19

520 Views

In statistics, the term "frequency" indicates the number of occurrences of a value in a given data sample. As a software meant for mathematical and scientific analysis, Pandas has many in-built methods to calculate frequency from a given sample.Absolute Frequency It is same as just the frequency where the number of occurrences of a data element is calculated. In the below example, we simply count the number of times the name of a city is appearing in a given DataFrame and report it out as frequency.Approach 1 − We use the pandas method named .value_counts.Exampleimport pandas as pd # Create ... Read More

Initialize Matrix in Python

Pavitra
Updated on 07-Aug-2019 07:23:19

2K+ Views

In this article, we will learn about how we can initialize matrix using two dimensional list in Python 3.x. Or earlier.Let’s see the intuitive way to initialize a matrix that only python language offers. Here we take advantage of List comprehension. we initialise the inner list and then extend to multiple rows using the list comprehension.Example# input the number of rows N = 3 # input the number of columns M = 3 # initializing the matrix res = [ [ i*j for i in range(N) ] for j in range(M) ] # printing the matrix on screen row ... Read More

Python Increment and Decrement Operators

Pavitra
Updated on 07-Aug-2019 07:21:40

583 Views

In this article, we will learn about increment and decrement operators in Python 3.x. Or earlier. In other languages we have pre and post increment and decrement (++ --) operators.In Python we don’t have any such operators . But we can implement these operators in the form as dicussed in example below.Examplex=786 x=x+1 print(x) x+=1 print(x) x=x-1 print(x) x-=1 print(x)Output787 788 787 786Other languages have for loops which uses increment and decrement operators. Python offers for loop which has a range function having default increment value “1” set. We can also specify our increment count as ... Read More

Absolute Deviation and Absolute Mean Deviation using NumPy

Pradeep Elance
Updated on 03-Jul-2020 07:47:01

869 Views

In Statistical analysis study of data variability in a sample indicates how dispersed are the values in a given data sample. The two important ways we calculate the variability are Absolute Deviation and  Mean Absolute Deviation.Absolute DeviationIn this method we first find the mean value of the given sample and then calculate the difference between each value and the mean value of the sample called as the absolute deviation value of each data sample. So for the values higher than mean the value the deviation value will be positive and for those lower than the mean value the deviation value ... Read More

Inbuilt Data Structures in Python

Pavitra
Updated on 07-Aug-2019 07:18:26

712 Views

In this article, we will learn about the 4 inbuilt data structures in python namely Lists, Dictionaries, Tuples & Sets.ListsA list is an ordered sequence of elements. It is a non-scalar data structure and mutable in nature. A list can contain distinct data types in contrast to arrays storing elements belonging to the same data types.Lists can be accessed by the help of the index by enclosing index within square brackets.Now let’s see an illustration to understand list better.Examplelis=['tutorialspoint', 786, 34.56, 2+3j] # displaying element of list for i in lis:    print(i) # adding an elements at end of ... Read More

A += B Assignment Riddle in Python

Pradeep Elance
Updated on 03-Jul-2020 07:49:19

64 Views

In this chapter we see what happens when we update the values in a tuple, which is actually immutable. We will be able to merge new values with old values but that throws an error. We can study the bytecode of the error and understand better how the rules for tuple work.First we define a tuple and then issue a command to update its last element as shown below.Example>>> tupl = (5, 7, 9, [1, 4]) >>> tupl[3] += [6, 8]OutputRunning the above code gives us the following result −Traceback (most recent call last): File "", line 1, in TypeError: ... Read More

id() function in Python

Pavitra
Updated on 07-Aug-2019 07:05:39

177 Views

In this article, we will learn about the usage and implementation of id() function in Python 3.x. Or earlier. It is present in Python Standard Library and is automatically imported before executing the code.Syntax: id ()Return value: Identity value of type The function accepts exactly one argument i.e. the name of the entity whose id has to be used. This id is unique for every entity until they are referring to the same data.Id’s are merely address in the memory locations and is used internally in Python.Example Codestr_1 = "Tutorials" print(id(str_1)) str_2 = "Tutorials" print(id(str_2)) # This will return True ... Read More

YouTube Media/Audio Download using Python - pafy

Hafeezul Kareem
Updated on 02-Jul-2020 14:07:57

828 Views

In this article, we will see how to extract details about Youtube videos and download them in different formats using the pafy module. Head over to the link for official documentation.Install the pafy module using the following commandpip install pafyIf you run the above command, it will generate the following results on the successful installation of the module pafy.Collecting pafy Using cached https://files.pythonhosted.org/packages/b0/e8/3516f761558525b00d3eaf73744eed5c267db 20650b7b660674547e3e506/pafy-0.5.4-py2.py3-none-any.whl Installing collected packages: pafy Successfully installed pafy-0.5.4Check whether you can import the pafy module or not by running the following command.import pafyIf you found no errors then it's done. Otherwise install the following module to solve ... Read More

*args and **kwargs in Python

Sarika Singh
Updated on 04-Apr-2023 11:40:53

232 Views

When we define a function in a python program, the purpose is to execute the code again and again by supplying different values to the function's arguments. One challenge in this design is, what if we are not sure about the number of arguments we want to process each time we call that function. This is where the special arguments called **args and **kwargs are needed. Let's look at them one by one.*argsThe *args enables us to use variable number of arguments as input to the function. In the below example we are finding out the result of multiplication of ... Read More

Advertisements