Python annotation #

Asked 1 years ago, Updated 1 years ago, 85 views

I'm a beginner at Python. I know Python annotations are there to explain how to organize code that doesn't help coding at all like C, but to encode text as utf-8 when thrusting it

 # -*- coding: utf-8 -*-
# # UTF-8 encoding when using korean
# # -*- coding:cp949 -*-*

You need to write these codes. Why do you do it while doing #?!?! Isn't it annotated? #-*-*- Does this have a special meaning?

python comment

2022-09-22 08:45

1 Answers

It is defined in the Python specification.

When encoding, the first or second line says to match the format you wrote in the question.

To be exact, write down the form ^[\t\v]*#.*?coding[:=][\t]*([-.a-zA-Z0-9]+).

https://www.python.org/dev/peps/pep-0263/


2022-09-22 08:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.