Categories
Python Answers

How to fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python?

Spread the love

Sometimes, we want to fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python.

in this article, we’ll look at how to fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python.

How to fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python?

To fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python, should tell the Python interpreter that our string is Unicode.

To do this, we write

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

def func():
    return '£'

to specify that the strings in the code is Unicode with

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

And then we can return '£' in func without errors.

Conclusion

To fix SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’ with Python, should tell the Python interpreter that our string is Unicode.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *