小编Bif*_*iff的帖子

Python中的两个正斜杠

我从基数排序中看到了这个代码示例:

def getDigit(num, base, digit_num):
    # pulls the selected digit
    return (num // base ** digit_num) % base
Run Code Online (Sandbox Code Playgroud)

什么是" //"在Python呢?

python floor-division

42
推荐指数
2
解决办法
2万
查看次数

Compact Python for()循环

如何将以下代码重新排列为简化列表解析?

for i in xrange(len(list)):
    if list[i].startswith('c'):
        list[i] = prefix + list[i]
Run Code Online (Sandbox Code Playgroud)

我尝试了以下但它似乎没有工作:

[prefix + list[i] for i in xrange(len(list)) if list[i].startswith('c')]
Run Code Online (Sandbox Code Playgroud)

以下内容将我抛弃:

list[i] = prefix + list[i]
Run Code Online (Sandbox Code Playgroud)

python

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

将继承的类构造函数参数传递给基础构造函数参数

将继承的类构造函数的参数传递基类构造函数的"C#方式"是什么?这是否需要覆盖基类中的base_model字符串?

// Base class
class vehicle
{
    private string base_model = String.Empty;

    vehicle(string model)
    {
        this.base_model = model;
    }

}


// Inherited classes
class tesla : vehicle
{
    private readonly string model = "Model S";      // This is unchanging

    tesla(string model) : base ( **pass model to base_model** )
    {
        // Initialize
    }
}

class ferrari : vehicle
{
    private readonly string model = "458 Spider";      // This is unchanging

    ferrari(string model) : base ( **pass model to …
Run Code Online (Sandbox Code Playgroud)

c# inheritance constructor

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

标签 统计

python ×2

c# ×1

constructor ×1

floor-division ×1

inheritance ×1