本文介绍了'\ b'(退格)的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习Python类,并且我刚刚了解了退格字符.像换行符(\ n)一样,退格键是ASCII码8的特殊字符.我的老师想不出使用它的理由,但是我很好奇它的用法.也许只是历史原因?当我尝试print("Hellow\b World")时,得到的正是我所期望的:Hello World.

I'm taking a Python class right now, and I just learned about the backspace character. Like newline (\n), backspace is a special character with ASCII code 8. My teacher couldn't think of a reason to use that, but I'm curious as to how it's used. Maybe just historical reasons? When I tried print("Hellow\b World"), I got just got what I expected: Hello World.

退格字符的原因是什么,如何使用?

What's the reason for the backspace character, and how might it be used?

我知道它不是特定于python的,但是在编写原始问题时,我主要是在考虑Python,却忘记了这一事实.我试图进行编辑以使其更清晰.

I am aware that it isn't python specific, but when writing the original question I was thinking mainly about Python and forgot this fact. I've tried to edit to make this more clear.

推荐答案

Backspace是控制字符,它将光标移至控制台中的一个字符,但不会将其删除.

Backspace is a control character that moves the cursor one character back in the console but doesn't delete it.

在ASCII世界中,它过去一直用于打印带有重音符号的字符.

It was used historically in the ASCII world to print accented characters.

例如à可以使用三个字符序列a Backspace`(或使用字符的十六进制值0x61 0x08 0x60)产生.

For example à could be produced using the three character sequence a Backspace ` (or, using the characters' hex values, 0x61 0x08 0x60).

有关退格的更多信息此处

退格键vs退格字符

很多人将两者混为一谈.键盘上的Backspace键几乎具有删除前一个字符的通用功能(=向后移动光标并删除该字符).但是,退格字符'\ b'仅将光标在控制台窗口中移回一个位置,而不会将其删除.

A lot of people confuse the two. Backspace key on keyboard has almost the universal function to delete the previous character (= move cursor back and delete that character). The backspace character '\b' however only moves the cursor one position back in the console window and doesn't delete it.

这篇关于'\ b'(退格)的用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:30