Found 10784 Articles for Python

Mathematical Functions in Python?

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

2K+ Views

From doing simple to complex mathematical operations(like trigonometric, logarithmic operations etc) in python we may need to use the math() module.The python math module is used to access mathematical functions. All methods of math() function are used for integer or real type objects but not for complex numbers.To use this function, we need to import it in our codeimport mathConstantsWe use these constants for calculation in python -ConstantsDescriptionsPiReturn the value of pi: 3.141592EReturn the value of natural base e. e is 0.718282tauReturns the value of tau. tau = 6.283185infReturns the infinitenanNot a number typeNumbers and Numeric RepresentationPython provides different functions ... Read More

Complex Numbers in Python?

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

17K+ Views

A complex number is created from real numbers. Python complex number can be created either using direct assignment statement or by using complex () function.Complex numbers which are mostly used where we are using two real numbers. For instance, an electric circuit which is defined by voltage(V) and current(C) are used in geometry, scientific calculations and calculus.Syntaxcomplex([real[, imag]])Creating a simple complex number in python>>> c = 3 +6j >>> print(type(c)) >>> print(c) (3+6j) >>> >>> c1 = complex(3, 6) >>> print(type(c1)) >>> print(c1) (3+6j)From above results, we can see python complex numbers are of type complex. Each complex ... Read More

Command Line and Variable Arguments in Python?

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

482 Views

Command Line ArgumentsCommand line arguments are input parameters which allow user to enable programs to act in a certain way like- to output additional information, or to read data from a specified source or to interpret the data in a desired format.Python Command Line ArgumentsPython provides many options to read command line arguments. The most common ways are -Python sys.argvPython getopt modulePython argparse modulePython sys moduleThe sys module stores the command line arguments (CLA) into a list and to retrieve it, we use sys.argv. It’s a simple way to read command line arguments as string.import sys print(type(sys.argv)) print('The command ... Read More

How to write an empty function in Python?

AmitDiwan
Updated on 11-Aug-2022 12:05:44

2K+ Views

In this article, we will see how we can create an empty functions in Python. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). Here, we will see examples of Empty Functions. Empty Function Use the pass statement to write an empty function in Python −Example # Empty function in Python def demo(): pass Above, ... Read More

Reloading modules in Python?

AmitDiwan
Updated on 16-Aug-2022 12:12:47

17K+ Views

The reload() is used to reload a previously imported module or loaded module. This comes handy in a situation where you repeatedly run a test script during an interactive session, it always uses the first version of the modules we are developing, even we have made changes to the code. In that scenario we need to make sure that modules are reloaded. The argument passed to the reload() must be a module object which is successfully imported before. Few points to understand, when reload() is executed − Python module’s code is recompiled and the module-level code re-executed, defining a ... Read More

Inplace vs Standard Operators in Python

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

325 Views

Inplace Operator in PythonInplace operation is an operation which directly changes the content of a given linear algebra or vector or metrices without making a copy. Now the operators, which helps to do this kind of operation is called in-place operator.Let’s understand it with an a simple example -a=9 a += 2 print(a)output11Above the += tie input operator. Here first, a add 2 with that a value is updated the previous value.Above principle applies to other operators also. Common in place operators are -+=-=*=/=%=Above principle applies to other types apart from numbers, for example -language = "Python" language +="3" print(language)OutputPython3Above ... Read More

Global and Local Variables in Python?

Arjun Thakur
Updated on 31-Aug-2023 02:52:46

11K+ Views

There are two types of variables: global variables and local variables. The scope of global variables is the entire program whereas the scope of local variable is limited to the function where it is defined.Example def func(): x = "Python" s = "test" print(x) print(s) s = "Tutorialspoint" print(s) func() print(x) OutputIn above program- x is a local variable whereas s is a global variable, we can access the local variable only within the function it is defined (func() above) and ... Read More

Counters in Python?

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

3K+ Views

A Counters is a container which keeps track to how many times equivalent values are added. Python counter class is a part of collections module and is a subclass of dictionary.Python CounterWe may think of counter as an unordered collection of items where items are stored as dictionary keys and their count as dictionary value.Counter items count can be positive, zero or negative integers. Though there is no restrict on its keys and values but generally values are intended to be numbers but we can store other object types too.InitializingCounter supports three forms of initialization. Its constructor can be called ... Read More

Time Functions in Python?

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

14K+ Views

Python provides library to read, represent and reset the time information in many ways by using “time” module. Date, time and date time are an object in Python, so whenever we do any operation on them, we actually manipulate objects not strings or timestamps.In this section we’re going to discuss the “time” module which allows us to handle various operations on time.The time module follows the “EPOCH” convention which refers to the point where the time starts. In Unix system “EPOCH” time started from 1 January, 12:00 am, 1970 to year 2038.To determine the EPOCH time value on your system, ... Read More

Transpose a matrix in Python?

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

3K+ Views

Transpose a matrix means we’re turning its columns into its rows. Let’s understand it by an example what if looks like after the transpose.Let’s say you have original matrix something like -x = [[1, 2][3, 4][5, 6]]In above matrix “x” we have two columns, containing 1, 3, 5 and 2, 4, 6.So when we transpose above matrix “x”, the columns becomes the rows. So the transposed version of the matrix above would look something like -x1 = [[1, 3, 5][2, 4, 6]]So the we have another matrix ‘x1’, which is organized differently with different values in different places.Below are couple ... Read More

Advertisements