Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Python cos

by suresh

The Python cos function is one of the Python Math function, which calculates the Trigonometry Cosine for the specified expression. The Python cos function returns the value between -1 and 1. In this section, we discuss how to use math cos function with example.

The mathematical formula behind the Python Trigonometry Cosine function is

COS(x) = Length of the Adjacent Side / Length of the Hypotenuse

The syntax of the cos Function in Python Programming Language is

math.cos(number);

Number: It can be a number or a valid numerical expression for which you want to find Cosine value.

  • If the number argument is a positive or negative number, the cos function returns the Cosine value.
  • If it is not a number, the cos function returns TypeError.

Python cos Function Example

The Python cos Function allows finding the trigonometry Cosine for the numeric values. In this example, we are going to find the Cosine values of different data types and display the output.

TIP: Please refer Python acos Function article to find the Arc Cosine of the specified Python expression.

# Python cos Function

import math

Tup = (1, 2, 3, -4 , 5)
Lis = [-1, 2, -3.5, -4 , 5]

print('Cosine value of Positive Number = %.2f' %math.cos(10))
print('Cosine value of Negative Number = %.2f' %math.cos(-15))

print('Cosine value of Tuple Item = %.2f' %math.cos(Tup[3]))
print('Cosine value of List Item = %.2f' %math.cos(Lis[2]))

print('Cosine value of Multiple Number = %.2f' %math.cos(10 + 20 - 40))
print('Cosine value of String Number = ', math.cos('Hello'))
Python COS Function

First, We declared Python List and Tuple with some random values. Next, we used the cos Function directly on both the Positive integer and negative integer. The following statements find the Cosine of the corresponding values.

print('Cosine value of Positive Number = %.2f' %math.cos(10))
print('Cosine value of Negative Number = %.2f' %math.cos(-15))

Next, We used the cos Function on Tuple and List items. If you see the above screenshot, the Python cos function is working perfectly on them.

print('Cosine value of Tuple Item = %.2f' %math.cos(Tup[3]))
print('Cosine value of List Item = %.2f' %math.cos(Lis[2]))

Next, We used the cos Math function on multiple values.

print('Cosine value of Multiple Number = %.2f' %math.cos(10 + 20 - 40))

Within the last statement, we tried cos Function on the String value, and it returns TypeError.

print('Cosine value of String Number = ', math.cos('Hello'))

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File Handling
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python numpy concatenate
  • Python numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python substring
  • Python Programming Examples

Copyright © 2021· All Rights Reserved.
About | Contact | Privacy Policy