有没有比此方法更Python化的方式来嵌套if语句:
def convert_what(numeral_sys_1, numeral_sys_2):
if numeral_sys_1 == numeral_sys_2:
return 0
elif numeral_sys_1 == "Hexadecimal":
if numeral_sys_2 == "Decimal":
return 1
elif numeral_sys_2 == "Binary":
return 2
elif numeral_sys_1 == "Decimal":
if numeral_sys_2 == "Hexadecimal":
return 4
elif numeral_sys_2 == "Binary":
return 6
elif numeral_sys_1 == "Binary":
if numeral_sys_2 == "Hexadecimal":
return 5
elif numeral_sys_2 == "Decimal":
return 3
else:
return 0
Run Code Online (Sandbox Code Playgroud)
该脚本是简单转换器的一部分。
从 Python 3.7开始,字典是有序的。那么为什么我不能通过索引获取键呢?
我想我在互联网上看到过类似的内容:Tkinter 使用双缓冲来避免闪烁。
这意味着什么以及如何以及在哪里?
我确信我误解了一些事情.
在类中实例化一个struct对象并将其作为构造函数中的值传递后,我得到一个错误?
错误:'test'不是一种类型
#include <iostream>
using namespace std;
struct Test
{
int x = 11;
int y = 22;
};
class A
{
private:
int foo = 100;
public:
A(Test tmp){}
};
class B
{
private:
Test test;
A a(test); //error
public:
B(){}
};
int main()
{
B b;
return 0;
}
Run Code Online (Sandbox Code Playgroud) python ×2
c++ ×1
dictionary ×1
if-statement ×1
python-3.x ×1
struct ×1
tk-toolkit ×1
tkinter ×1