标识符与关键字

标识符

标识符 是指用来标识某个实体的一个符号,在不同的应用环境下有不同的含义。
在计算机编程语言中,标识符是用户编程时使用的名字,用于给变量、常量、函数、语句块等命名,以建立起名称与使用之间的关系。
标识符通常由字母和数字以及其它字符构成。

特别地,标识符的第一个位置不能是数字。
例如, 是合法的, 是不合法的。

以下为各种语言的标识符介绍:

C++ : cppreference.com
Java : docs.oracle.com
Python : docs.python.org

关键字

每种语言都会有一些特殊的标识符,我们称之为“关键字”或者“保留字”。
部分关键字虽然没有实际作用,但仍然不能被用作变量名。
另外,还有一些关键字被叫做“软关键字”或者“上下文关键字”,只要不在对应语境下,也可以用作变量名(不建议这么做)。

C++

Reserved Keyword
alignas compl explicit or this
alignof concept export or_eq thread_local
and const extern private throw
and_eq consteval false protected true
asm constexpr float public try
atomic_cancel constinit for reflexpr typedef
atomic_commit const_cast friend register typeid
atomic_noexcept continue goto reinterpret_cast typename
auto contract_assert if requires union
bitand co_await inline return unsigned
bitor co_return int short using
bool co_yield long signed virtual
break decltype mutable sizeof void
case default namespace static volatile
catch delete new static_assert wchar_t
char do noexcept static_cast while
char8_t double not struct xor
char16_t dynamic_cast not_eq switch xor_eq
char32_t else nullptr synchronized
class enum operator template
identifiers with special meaning
final transaction_safe import pre trivially_relocatable_if_eligible
override transaction_safe_dynamic module post replaceable_if_eligible

Java

Reserved Keyword
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
_

上面这个 _ 是下划线 。

Contextual Keyword
exports opens requires uses yield
module permits sealed var
non-sealed provides to when
open record transitive with

Python

Reserved Keyword
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
Soft Keyword
_ case match type

上面这个 _ 是下划线 。

以下为各种语言的关键字介绍:

C++ : cppreference.com
Java : docs.oracle.com
Python : docs.python.org