atan2() function in Python Last Updated : 14 Mar, 2018 Comments Improve Suggest changes Like Article Like Report atan2(y, x) returns value of atan(y/x) in radians. The atan2() method returns a numeric value between -\pi and \pi representing the angle \theta of a (x, y) point and positive x-axis. Syntax : atan2(y, x) Parameter : (y, x) - Both must be a numeric value. Returns : Returns atan(y / x), in radians. The double value is \theta from polar coordinate (r, theta). TypeError : Returns a TypeError if anything other than float is passed. Code #1 : Python3 1== # Python3 program to demonstrate # the atan2() method # imports math import math # prints the theta value of # two negative co-ordinates theta1 = math.atan2(-0.9, -0.9) print("atan2(-0.9, -0.9) : ", theta1) # prints the theta value of # two positive co-ordinates theta2 = math.atan2(1.2, 1.5) print("atan2(1.2, 1.5) : ", theta2) # prints the theta value of one # positive and one negative co-ordinates theta3 = math.atan2(1.2, -1.5) print("atan2(1.2, -1.5):", theta3) Output : atan2(-0.5, -0.5): -2.356194490192345 atan2(1.2, 1.5): 0.6747409422235526 atan2(1.2, -1.5): 2.4668517113662407 Code #2 : Python3 # Python3 program to demonstrate the atan() method # imports math import math # list containing x and y coordinates y = [1, 2, 3, 4] x = [6, 3, 7, 8] # traversing in range to get theta # for all y and x co-ordinates for i in range(len(x)): theta = math.atan2(y[i], x[i]) print(theta) Output : 0.16514867741462683 0.5880026035475675 0.40489178628508343 0.4636476090008061 Code #3 : Program demonstrating the error Python3 # Python3 program to demonstrate the # TypeError in atan() method # importing math import math y, x = 3, 6 # when integer values are passed # it returns a TypeError theta = math.atan2([y], [x]) print(theta) Output : Traceback (most recent call last): File "/home/622586ab389561bcdbfff258aca01e65.py", line 9, in theta = math.atan2([y],[x]) TypeError: a float is required Practical Application : This function is used to find the slope in radians when Y and X co-ordinates are given. Code #4 : Python3 1== # Let's find the slope when X # and Y co-ordinates are given # imports math import math # X and Y are co-ordinates X = 2; Y = 2 # slope in radians theta1 = math.atan2(Y, X) # print the Slope in radians print(theta1) Output : 0.7853981633974483 Comment More infoAdvertise with us Next Article atan2() function in Python S Striver Follow Improve Article Tags : Misc Python Python-Built-in-functions Practice Tags : Miscpython Similar Reads Python int() Function The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part.Example:In this example, we passed a string as an argument to the int() function and printed it.Pythonage = "21" print("age =", int(age) 3 min read Python Built in Functions Python is the most popular programming language created by Guido van Rossum in 1991. It is used for system scripting, software development, and web development (server-side). Web applications can be developed on a server using Python. Workflows can be made with Python and other technologies. Databas 6 min read Python 3 - input() function In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string.Python input() Function SyntaxSyntax: input(prompt)Parameter:Prompt: (optional 3 min read atan2() function in C++ STL The atan2() is an inbuilt function in C++ STL which returns tangent inverse of (y/x), where y is the proportion of the y-coordinate and x is the proportion of the x-coordinate. The numeric value lies between -\pi and \pi representing the angle \theta of a (x, y) point and positive x-axis. It is the 3 min read Python len() Function The len() function in Python is used to get the number of items in an object. It is most commonly used with strings, lists, tuples, dictionaries and other iterable or container types. It returns an integer value representing the length or the number of elements. Example:Pythons = "GeeksforGeeks" # G 2 min read hex() function in Python hex() function in Python is used to convert an integer to its hexadecimal equivalent. It takes an integer as input and returns a string representing the number in hexadecimal format, starting with "0x" to indicate that it's in base-16. Example:Pythona = 255 res = hex(a) print(res)Output0xff Explanat 2 min read How to call a function in Python Python is an object-oriented language and it uses functions to reduce the repetition of the code. In this article, we will get to know what are parts, How to Create processes, and how to call them.In Python, there is a reserved keyword "def" which we use to define a function in Python, and after "de 5 min read Python Functions Python Functions is a block of statements that return the specific task. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it ov 11 min read pow() Function - Python pow() function in Python is a built-in tool that calculates one number raised to the power of another. It also has an optional third part that gives the remainder when dividing the result. Example:Pythonprint(pow(3,2))Output9 Explanation: pow(3, 2) calculates 32 = 9, where the base is positive and t 2 min read cmp() function - Python cmp() method in Python 2.x compares two integers and returns -1, 0, 1 according to comparison. cmp() does not work in python 3.x. You might want to see list comparison in Python.ExamplePython# Example 1 print(cmp(3, 4)) # Example 2 print(cmp(5, 5)) # Example 3 print(cmp(7, 6)) Output-101ExplanationI 3 min read Like