小编Usu*_*sus的帖子

我在 python 中使用 map 函数有困难

我对python很陌生。
我研究了我的问题,但无法得到例外的答案。
我在这里不明白的是myfunc它是如何被调用的,因为它没有像这样的参数myfunc()以及参数如何 (n)采用两个参数(苹果和香蕉)?

    def myfunc(n):
        return len(n)

    x = list(map(myfunc,('apple', 'banana')))
    print(x)
   
    output:
    [5,6]
Run Code Online (Sandbox Code Playgroud)

python map-function

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

难以理解 C++ 字符串文字

下面的代码是我的程序的一部分。它不执行它说 c++ 禁止将字符串常量转换为 char*。我该如何解决这个错误?

#include <cstring>
#include <iostream>
using namespace std;

class Bank
{
private:
    char name[20];
    int acc;
    float amount;

public:
    Bank()
    {
        strcpy("",name);
        acc = 0;
        amount = 0;
    }

    void open(int a)
    {
        cout << "Enter name:";
        cin >> name;
        acc = a;
        cout << "Enter Amount" << endl;
        cin >> amount;
    }

    void edit(int flag, float a);
};

int main()
{
    Bank B[10];
}  
Run Code Online (Sandbox Code Playgroud)

c++ string

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

标签 统计

c++ ×1

map-function ×1

python ×1

string ×1