2023.4.13

一、组织代码:

python通过缩进来组织代码,缩进时,几个空格都是允许的,但是数目必须统一,我们通常用四个空格表示一个缩进。tab一次是四个空格。
使用行\,加这个符号后,可以换行再敲代码,不会直接运行。

二、对象 包含id \type\value
>>> a = 3
>>> id(a)
1935636523376
>>> id(3)
1935636523376
>>> type(3)
<class 'int'>
>>> b = "woaini"
>>> print(b)
woaini
>>> id(b)
1935676502768
>>> type(b)
<class 'str'>
>>

#对象就是一个内存块,一个个车位一样,有编号称为id(计算机内存地址),有类型,有可打印值
变量就是对象的引用,因为变量存储的就是对象的地址,变量通过地址引用了对象。变量位于栈zhan内存;对象位于堆内存。
python是动态类型的语言,变量不需要显示声明类型,根据变量引用的对象,python讲究语法的简洁,会自动解释数据类型。
但是每个对象都有数据类型,只支持该类型支持的操作。如果不支持的类型,就会报错。

比如:
>>> a = 3 + 10
>>> print(a)
13
>>>  a = 3 + m
Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    a = 3 + m
NameError: name 'm' is not defined
>>

三、标识符:给变量(后面还会学到函数、类、模块等)起名字的一些规则
1、区分大小写,大小写不同含义是不同的 ;
2、第一个字符必须是字母或者是下划线,后面的字符必须是字母、下划线、数字。其他的不可以。
3、不能使用关键词命名,比如 if or 等。
4、以双下划线开头和结尾的名称通常有特殊含义,避免这种写法。比如_init_是类的构造函数
5、关键词有哪些
False def if raise None del import return True elif in try and else is while as except lambda with......
>>> sat = 123
>>> if = 333
SyntaxError: invalid syntax

四、小tips:使用help 查询关键词

或者在idle页面按F1也可以查询一些信息,比如turtle的使用规则。
>>> help()

Welcome to Python 3.9's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.9/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

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

help> quit

记得要退出之后才会又回到交互模式哦。

五、今日疑问

对象之后空格然后再输入,可以把空格省略掉吗?

a = 3

a=3是否可行呢?

`nlohmann::json` 是一个流行的 C++ JSON 库,它提供了一个非常方便的方式来处理 JSON 数据。这个库被广泛使用在 C++ 项目中,用于解析、序列化和反序列化 JSON 数据。通过包含 nlohmann 的 JSON 库,你可以轻松地将 C++ 数据结构转换为 JSON 格式,或者将 JSON 字符串转换为 C++ 数据结构。 在 C++ 中使用 `nlohmann::json` 库通常涉及以下几个步骤: 1. 包含库头文件:首先,你需要在你的 C++ 文件中包含 `nlohmann::json` 库的头文件,通常只需要一行代码:`#include <nlohmann/json.hpp>`。 2. 创建 JSON 对象:你可以创建 `json` 类型的对象,并使用它来构建 JSON 结构。例如,你可以创建一个空的 JSON 对象或者数组,或者使用花括号初始化器语法来创建包含数据的 JSON 对象。 3. 使用 JSON 对象:你可以使用操作符、成员函数等来访问和修改 JSON 对象的内容。你可以添加、删除键值对,或者查询它们。 下面是一个简单的使用示例: ```cpp #include <iostream> #include <nlohmann/json.hpp> using json = nlohmann::json; // 定义一个别名,简化后续使用 int main() { // 创建一个 JSON 对象 json j = { {"name", "John Doe"}, {"age", 35}, {"is_student", false} }; // 输出这个 JSON 对象 std::cout << j.dump(4) << std::endl; // 修改 JSON 对象中的某个值 j["age"] = 36; // 输出修改后的 JSON 对象 std::cout << j.dump(4) << std::endl; return 0; } ``` 在这个例子中,我们首先创建了一个包含几个键值对的 JSON 对象。然后我们输出了这个对象的格式化字符串表示,并修改了其中一个值。最后,我们再次输出了对象。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值