讲师中心 微信公众号

工具推荐

视频效率加速
Laper
Laper

剧本策划到成片协作

Loomy
Loomy

AI助理适用自媒体、办公、日程等场景

立刻MV
立刻MV

低成本歌曲 MV、视频生成

AniShort
AniShort

AI短剧协同制作平台

Is type a Keyword in C or Python?

轻伟吖_9921

轻伟吖_9921

发布时间:2026-12-05 08:37:14

|

160人浏览过

|

来源于php中文网

原创

Is type a Keyword in C or Python?

type is not a C keyword nor a Python reserved keyword—it’s a descriptive identifier used in the Python C API to denote type objects (e.g., type PyTypeObject), and in Python it’s a built-in class name that can even be shadowed as a variable (though discouraged).

`type` is not a c keyword nor a python reserved keyword—it’s a descriptive identifier used in the python c api to denote type objects (e.g., `type pytypeobject`), and in python it’s a built-in class name that can even be shadowed as a variable (though discouraged).

In the Python C API documentation, the line type PyTypeObject does not mean that type is a keyword or a C language construct like struct or typedef. Instead, it’s a convention—a human-readable label indicating that PyTypeObject represents a type object, i.e., the C-level structure underlying Python classes and types. This usage predates any syntactic role of type in Python itself and serves purely as documentation-oriented notation.

For example, this snippet from the C API is not valid C code on its own:

type PyTypeObject;  // ❌ Not legal C — 'type' is not a keyword or typedef

What’s actually defined in <object.h></object.h> is:

typedef struct _typeobject {
    // ... fields ...
} PyTypeObject;

So PyTypeObject is a typedef’d struct, and the word type in type PyTypeObject is simply an editorial annotation—not part of the syntax.

立即学习“Python免费学习笔记(深入)”;

Zhihu Keyword Content Search
Zhihu Keyword Content Search

爬取知乎问题和回答。当用户请求爬取/抓取/搜索知乎时触发。支持关键词搜索、按回答数排序、抓取全部回答并保存为JSON或纯文本。

下载

In Python, type is a built-in class, not a reserved keyword:

>>> type(42)
<class 'int'>
>>> type
<class 'type'>
>>> type = "I just overwrote type!"  # ✅ Valid (but dangerous!)
>>> type(42)  # ❌ AttributeError: 'str' object has no attribute '__call__'

⚠️ While technically allowed, reassigning type (or other built-ins like list, dict) breaks introspection and type checking—and should be avoided in production code.

One nuance: Starting with Python 3.12, type became a soft keyword—but only in the context of PEP 695 type parameter declarations:

type Point[T] = tuple[T, T]  # ✅ 'type' is a soft keyword here
x: type[int] = 42            # ❌ Still invalid — 'type' is NOT a soft keyword in annotations

Even then, soft keywords are context-sensitive: type remains freely usable as an identifier elsewhere (for type in types:, def func(type=None):, etc.).

In summary:

  • In C API docs, type is a descriptive label, not syntax.
  • In Python, type is a built-in class—reassignable but strongly discouraged.
  • Since 3.12, type gains soft-keyword status only in type X[...] = ... declarations—never globally.

相关文章

WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
SoundView
SoundView Hot

SoundView是一款面向跨境电商的视频翻译、配音和本地化 AI 创作平台。

WorkBuddy

一款AI办公效率工具,主要用于腾讯云推出的AI原生桌面智能体工作台,适合需要提升相关任务效率的用户。

豆包大模型

豆包大模型是一款由字节跳动推出的企业级大语言模型服务平台。

AiPPT插件

一款内嵌于PowerPoint和WPS、整合AI生成与设计工具的PPT插件。

DeepSeek

DeepSeek是一款面向对话、写作、编程和推理场景的AI大模型工具。

爆赞AI
爆赞AI Hot

一款整合画布、多模型生成和创作模板的AI视频制作平台。

立刻MV
立刻MV Hot

立刻MV是一款AI文本写作工具,AI 音乐视频(MV)创作工具。

Laper
Laper Hot

Laper是专为编剧、导演和制片人推出的 AI 原生剧本创作工具。

墨刀AI
墨刀AI Hot

一款AI图像与设计工具,主要用于产品经理的专属智能体,适合需要提升相关任务效率的用户。

相关专题

更多
python打包成可执行文件
python打包成可执行文件

本专题为大家带来python打包成可执行文件相关的文章,大家可以免费的下载体验。

2071

2023.07.20

python能做什么
python能做什么

python能做的有:可用于开发基于控制台的应用程序、多媒体部分开发、用于开发基于Web的应用程序、使用python处理数据、系统编程等等。本专题为大家提供python相关的各种文章、以及下载和课程。

6084

2023.07.25

format在python中的用法
format在python中的用法

Python中的format是一种字符串格式化方法,用于将变量或值插入到字符串中的占位符位置。通过format方法,我们可以动态地构建字符串,使其包含不同值。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

1989

2023.07.31

python教程
python教程

Python已成为一门网红语言,即使是在非编程开发者当中,也掀起了一股学习的热潮。本专题为大家带来python教程的相关文章,大家可以免费体验学习。

38117

2023.08.03

python环境变量的配置
python环境变量的配置

Python是一种流行的编程语言,被广泛用于软件开发、数据分析和科学计算等领域。在安装Python之后,我们需要配置环境变量,以便在任何位置都能够访问Python的可执行文件。php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

4367

2023.08.04

python eval
python eval

eval函数是Python中一个非常强大的函数,它可以将字符串作为Python代码进行执行,实现动态编程的效果。然而,由于其潜在的安全风险和性能问题,需要谨慎使用。php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

4367

2023.08.04

scratch和python区别
scratch和python区别

scratch和python的区别:1、scratch是一种专为初学者设计的图形化编程语言,python是一种文本编程语言;2、scratch使用的是基于积木的编程语法,python采用更加传统的文本编程语法等等。本专题为大家提供scratch和python相关的文章、下载、课程内容,供大家免费下载体验。

1343

2023.08.11

python合并两个列表
python合并两个列表

Python是一种强大的编程语言,具有许多方便的功能和工具。在Python中,有多种方法可以合并两个列表。php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

656

2023.08.10

PHP 8.6依赖注入教程合集
PHP 8.6依赖注入教程合集

服务容器负责创建对象和装配依赖,能减少PHP项目中重复的初始化代码。本专题结合PHP 8.6与Symfony的实际用法,从依赖配置讲到服务生命周期,帮助理清对象何时创建、如何释放,以及配置改变后怎样生效。

0

2026.12.04

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn