小编her*_*ity的帖子

为什么print("text"+ str(var1)+"more text"+ str(var2))被描述为"被拒绝"?

为什么下面的代码在'Snakes and Coffee'的评论中被称为'古老的不赞成的方法'到Blender 在python打印多个参数的帖子?它与Python 2或Python 3的后端代码/实现有关吗?

print("Total score for " + str(name) + " is " + str(score))
Run Code Online (Sandbox Code Playgroud)

python string-formatting python-2.7 python-3.x

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

Python tkinter:消息小部件中锚选项的正确值是什么?

我一直在通过http://www.python-course.eu/tkinter_message_widget.php学习 tkinter

当我使用网站上提供的选项添加锚选项时,我不断收到错误消息。有人告诉我 NE 不存在,但在上面的链接中 NE 作为锚选项给出:

NameError: name 'NE' is not defined
Run Code Online (Sandbox Code Playgroud)

这是我的代码。

import tkinter

root = tkinter.Tk()
message = ("Whatever you do will be insignificant,"
"but it is very important that you do it.\n"
"(Mahatma Gandhi)")

msg = tkinter.Message(root,text = message, anchor = NE, aspect = 1000,
                      foreground='red', background='yellow', 
                      highlightcolor='green', highlightthickness=0,
                      borderwidth=500)
#msg.config(bg='lightgreen', font=('times', 24, 'italic'))
msg.pack()
tkinter.mainloop()
Run Code Online (Sandbox Code Playgroud)

编辑:我也尝试在单引号中输入“NE”,但没有奏效。

python user-interface tkinter python-2.7 python-3.x

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

为什么Matlab警告我"预先分配不推荐"

当我在Matlab中遇到警告时,我正在为Andrew Ng编写Coursera机器学习课程的函数.我没有写出答案应该是什么,但起始代码全部在这里,除了一行用于解释目的.问题不是捕获问题的答案,而是解释Matlab的警告.

我得到的警告(不是错误)说:

Line 6: The variable 'g' appears to be preallocated but preallocation is not recommended here 
Run Code Online (Sandbox Code Playgroud)

这是代码

function g = sigmoid(z)
%SIGMOID Compute sigmoid function
%   g = SIGMOID(z) computes the sigmoid of z.

% You need to return the following variables correctly 
g = zeros(size(z));

% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
%               vector or scalar).

g = 1./z;

% =============================================================

end
Run Code Online (Sandbox Code Playgroud)

matlab

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

Leetcode上“岛屿数量”的DFS和BFS时空复杂性

是问题描述。建议的前两个解决方案涉及DFS和BFS。这个问题涉及第一种方法:DFS和BFS。

我将问题陈述包括在此处,以便于阅读。

Given a 2d grid map of '1's (land) and '0's (water), count the number of 
islands. An island is surrounded by water and is formed by connecting adjacent
lands horizontally or vertically. You may assume all four edges of the grid are 
all surrounded by water.

    Example 1:

    Input:
    11110
    11010
    11000
    00000

    Output: 1


    Example 2:

    Input:
    11000
    11000
    00100
    00011

    Output: 3
Run Code Online (Sandbox Code Playgroud)

对于DFS和BFS的时间复杂度为何同时存在,我不清楚O(rows * columns)。我看到网格只是充满0的情况是怎么回事-我们只需要检查每个单元格即可。但是,DFS方法是否不会增加搜索时间?即使我们通过0在dfs方法中将访问的单元格标记为来标记它们,由于两个外部循环,我们仍然会重新访问所有单元格。如果在行数和列数较大的大网格中dfs的时间复杂度为O(n),那么时间复杂度不是O(行*列* max [rows,cols])吗?此外,是不一样的情况下,与BFS方法,即它是O(rows * …

algorithm big-o breadth-first-search depth-first-search

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

结构体定义后的变量名

下面是什么bar以及x为什么它们位于那里?它们是 s 的实例吗struct

我正在阅读这个Stackoverflow 问题,我已将其代码粘贴到此处,我发现海报和答案bar之一xstruct. cpp 参考在其示例中不使用此语法,我不知道该语法被称为什么,也不知道该语法如何查找它。

如果只是创建 a 的实例struct,为什么不像cpp Reference在其示例中那样将其写在下一行中呢?

struct _bar_ 
    {
        int a;
    } bar; 
Run Code Online (Sandbox Code Playgroud)
struct test {
      int value;
   } x;
Run Code Online (Sandbox Code Playgroud)

c++ syntax struct c++11

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

什么是 tkinter 中的“屏幕单位”?

我正在阅读下面链接中的回复并遇到“屏幕单位”,但我无法在吉姆丹尼的回复中找到“屏幕单位”究竟指的是什么。我知道它们不是像素。

如何使用 Tkinter 创建填充窗口宽度的换行文本?

python user-interface tkinter

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

os.access()方法中os.F_OK模式下'f'的含义

我试图理解os.access()方法模式中各个字母代表什么。其他的很清楚(为了清晰起见,大写字母):

os.R_OK- 检查可读性

os.W_OK- 检查可写性

os.X_OK- 检查可执行性

但是 F 代表什么os.F_OK?存在中没有“F”。

python operating-system module

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

SDL:"在C++中本地工作"是什么意思?

我试图得到上面这句话的一般意义.我正在学习PyGame并遇到了SDL(Simple DirectMedia Layer)参考.

从PyGame引用SDL:"Pygame是SDL的python包装器,由Pete Shinners编写." http://www.pygame.org/docs/tut/newbieguide.html

我查找了SDL(上面的URL中的SDL链接[只需单击SDL])并进入"SDL用C语言编写,本机与C++一起工作,......"这里:http://libsdl.org/

我已经考虑过"本机"一词来暗示原始环境,但我不明白为什么用C语言编写的东西在C语言中不是原生的,而是C++中的原生语言?

这句话是否意味着它在C++中同样有效?

c++ python pygame sdl python-2.7

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

string_view 和 basic_string<char> 之间的联系是什么?为什么 string_view 示例代码不起作用?

我已经从 Bjarne Stroustrup 的C++ 之旅中复制了代码来测试字符串视图,但我不断收到错误:

\n
error: no matching function for call to \xe2\x80\x98std::__cxx11::basic_string<char>::basic_string(std::basic_string_view<char>::size_type\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用 VS CodeWSL 2Ubuntu 20.04gcc-11

\n

在 中main.cpp,我有:

\n
#include <iostream>\n#include "strings.h"\n\nusing namespace std;\n\nint main () {\n    string king = "Harold";\n    auto s1 = cat(king, "William");\n}\n
Run Code Online (Sandbox Code Playgroud)\n

strings.h,我有以下内容。该函数按照教科书上的内容复制。我把它打出来是为了避免*出现具有不同编码的特殊字符。

\n
#pragma once\n#include <string>\n\nusing namespace std;\n\nstring cat(string_view sv1, string_view sv2) {\n    string res(sv1.length()+sv2.length());\n    char* p = &res[0];\n\n    for (char c : sv1)                  // one way\n …
Run Code Online (Sandbox Code Playgroud)

c++ string-view windows-subsystem-for-linux c++20 wsl-2

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

为什么常量CLOCKS_PER_SEC不需要用std ::命名空间,但是<ctime> clock()和clock_t呢?

我正在尝试使用<ctime>库来获得类型感clock_t,clock()函数和常量CLOCKS_PER_SEC.我注意到,我会命名空间都clock_tclock()std::但不CLOCKS_PER_SEC.这是为什么?如何CLOCKS_PER_SEC自己浮动?

#include <ctime>
#include <iostream>

int main() {
  std::clock_t start;
  double duration;

  start = std::clock();

  for (long int i = 0; i < 10000000000; i ++){
    // do something
  }

  duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;

  std::cout << duration << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ c++11 c++14

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