Print Degree Symbol in Python

Print Degree Symbol in Python

  1. The Degree Symbol
  2. Print the Degree Symbol in Python Using the chr Function
  3. Print the Degree Symbol in Python Using F-String

This tutorial will teach us how to write the degree symbol in Python.

The Degree Symbol

A degree symbol is a symbol that indicates the temperature of a particular area. For example, suppose it is 34 degrees Celcius in Karnataka; it suggests that, in the state of Karnataka, India, the temperature is 34 degrees.

Degrees are also used with Fahrenheit along with Celcius.

Let us learn how to print the degree symbol in Python. However, it is vital to understand the chr function in Python before we do that.

The characters within the function from 0-97 are alphanumeric. After that, one can print special characters using the chr function.

One can use the following code block to display or print the degree symbol in Python.

print(chr(176))

The output of the code above can be illustrated as follows.

°

We can also write it along with a temperature. This operation can be performed with the help of the following block of code in Python.

print("23", chr(176), sep = '')

The output of the code block mentioned above is as follows.

23°

Note: The sep function indicates the space between the symbol and the temperature value.

F-string is yet another format in Python that helps us present strings and characters in a particular manner. One can print the degree symbol in Python with the help of the following block of code.

Temp = 22

print(f"Temperature {Temp}\N{DEGREE SIGN}.")

The output of the code block mentioned above can be illustrated as follows.

Temperature 22°.

Thus, we have successfully explored two different ways by which we can print the degree symbol in Python.

Preet Sanghavi avatar Preet Sanghavi avatar

Preet writes his thoughts about programming in a simplified manner to help others learn better. With thorough research, his articles offer descriptive and easy to understand solutions.

LinkedIn GitHub

Related Article - Python Symbol

  • @ Symbol in Python