小编Mod*_*art的帖子

有没有更好的方法在python中编写嵌套的if语句?

有没有比此方法更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 if-statement

27
推荐指数
3
解决办法
719
查看次数

为什么我无法通过索引获取字典键?

从 Python 3.7开始,字典是有序的。那么为什么我不能通过索引获取键呢?

python dictionary python-3.x

5
推荐指数
1
解决办法
1110
查看次数

Tkinter 中的双缓冲是什么意思?

我想我在互联网上看到过类似的内容:Tkinter 使用双缓冲来避免闪烁。
这意味着什么以及如何以及在哪里?

tk-toolkit tkinter

3
推荐指数
1
解决办法
353
查看次数

为什么struct对象不是一个类型?

我确信我误解了一些事情.

在类中实例化一个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)

c++ struct

0
推荐指数
1
解决办法
81
查看次数