例如在python3中定义函数的参数时,使用list和List有什么区别?例如,有什么区别
def do_something(vars: list):
Run Code Online (Sandbox Code Playgroud)
和
def do_something(vars: List):
Run Code Online (Sandbox Code Playgroud)
该文件说:
类打字。列表(列表,MutableSequence[T])
列表的通用版本。用于注释返回类型。
但我不完全确定以上是什么意思。
我有类似的问题:dict vs dict、set vs set等。
我意识到之前已经问过这个问题(Python Pyplot Bar Plot bars在使用log scale时消失了),但给出的答案对我来说不起作用.我设置了我的pyplot.bar(x_values,y_values等,log = True)但是出现了一个错误:
"TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'"
Run Code Online (Sandbox Code Playgroud)
我一直在寻找一个pyplot代码的实际例子,该代码使用条形图,y轴设置为log但尚未找到它.我究竟做错了什么?
这是代码:
import matplotlib.pyplot as pyplot
ax = fig.add_subplot(111)
fig = pyplot.figure()
x_axis = [0, 1, 2, 3, 4, 5]
y_axis = [334, 350, 385, 40000.0, 167000.0, 1590000.0]
ax.bar(x_axis, y_axis, log = 1)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
即使我删除了pyplot.show,我也会收到错误.在此先感谢您的帮助
假设我将一个非常长的等式输入到单行c代码(.c或.h文件)中,该代码长达数千(可能是数万)字符; 例如
y = (2*(36*pow(x,2)*pow(A[n][j],5)*B[n][j]
+ (several thousand more such expressions) ) ;
Run Code Online (Sandbox Code Playgroud)
(这里只是将x作为变量,A,B作为双指针等).在说gcc编译器无法正确编译代码之前,.c或.h文件中的代码行有多长?我已经为#c阅读了几个关于这个问题的相关讨论,但不仅仅是简单的c.我从来没有从gcc中收到任何关于我的代码中包含太长行的错误,但我想对这一点更加确定.
编辑:在回应下面的一些评论时,我现在意识到我问了两个(我认为密切相关的)问题:
(1)在gcc编译器可能发生错误/引发错误之前,行中c可以有多长时间有限制吗?
(2)在gcc编译器可能发生错误/引发错误之前,表达式的复杂程度是否有限制?(例如,我们可以将很长的一行分成几行,但它们都是同一个表达式的一部分).
我有以下结构,
struct example_struct {
int number ;
char word[100]
}
Run Code Online (Sandbox Code Playgroud)
我在我的代码中初始化为一个常量结构
const struct example_struct example {
.number = 5
} ;
strcpy(example.word, "some_string") ;
Run Code Online (Sandbox Code Playgroud)
当我尝试编译代码时,它给了我警告:
"警告:传递'strcpy'的参数1从指针目标类型中丢弃'const'限定符"
我意识到当我将它作为const结构时,我不应该尝试分配结构的值,但是我也不能将stringcpy放在结构中.有什么办法可以将字符串赋给c中const结构的元素吗?