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

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.