SyntaxError: Non-ASCII character

A fairly typical error for those who use Cyrillic characters or any other characters outside ASCII.

File "args_demo.py", line 21 SyntaxError: Non-ASCII character '\xd0' in file args_demo.py on line 21, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

pep-0263

Perhaps the encoding problem can be solved by adding the required one to the beginning of the file

# coding=utf-8

Instead of utf-8, you can try cp1251, iso-8859-15 or another encoding that you suspect.

To change the file encoding in Windows you can open it in Notepad and save it (Save As → Encoding) in a different encoding

For changing the encoding in Linux you can read here

↓ Python articles ↓
Development in Python
Interactive mode
Virtual environment
str: strings
\: line break
Lists
Loops
Methods
Functions
*args **kwargs
enum
Determine a Python variable type
Testing with Python
Working with REST API in Python
Files: write, read, append, context manager…
Download a file over the network
SQLite3: working with a database
datetime: Date and Time in Python
Selenium + Python
Difficulties when working with Python
DJANGO
Flask
Script for a ZPL printer
socket :Python Sockets
subprocess: run bash commands from Python
multiprocessing: several processes at once
psutil: system resources
sys.argv: command line arguments
PyCharm: IDE
pydantic: data validation
paramiko: SSH from Python
enumerate
json.dumps

Article author: Andrei Olegovich