相关疑难解决方法(0)

什么时候"i + = x"与Python中的"i = i + x"不同?

我被告知+=可以有不同于标准符号的效果i = i +.有没有在这情况下i += 1会从不同i = i + 1

python operators

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

当b是列表时,为什么b + =(4,)有效而b = b +(4,)不起作用?

如果我们采取b = [1,2,3]并尝试这样做:b+=(4,)

它返回b = [1,2,3,4],但是如果我们尝试这样做b = b + (4,)是行不通的。

b = [1,2,3]
b+=(4,) # Prints out b = [1,2,3,4]
b = b + (4,) # Gives an error saying you can't add tuples and lists
Run Code Online (Sandbox Code Playgroud)

我预计b+=(4,)会失败,因为您无法添加列表和元组,但它确实有效。因此,我尝试b = b + (4,)期望得到相同的结果,但是没有用。

python tuples list python-3.x

75
推荐指数
3
解决办法
5395
查看次数

Pascal及其当前的应用

我在1997年学习了Turbo Pascal,我非常喜欢它作为一种语言.一切都非常有条理,编译器确保你以正确的方式做事.我后来尝试过Delphi但从未对它感兴趣.

从那时起,我使用了许多不同的编程和脚本语言(C,C++,PHP,Python,Perl,TCL),最近我开始考虑我的旧Turbo Pascal时代.

所以,我想知道Pascal在今天可能有用的实用目的以及可用的API和框架.有没有人在现代开发环境中使用Pascal或者它只是一种死语言?

澄清我的问题:Pascal可以用于现代应用程序开发.它是否被使用以及如何使用?

维基百科链接或快速谷歌搜索无济于事,我一直在那里.这就是我问"专家"的原因.

pascal

33
推荐指数
8
解决办法
3万
查看次数

在循环中切片NumPy数组

我需要一个很好的解释(参考)来解释(for)循环中的NumPy切片.我有三个案子.

def example1(array):
    for row in array:
        row = row + 1
    return array

def example2(array):
    for row in array:
        row += 1
    return array

def example3(array):
    for row in array:
        row[:] = row + 1
    return array
Run Code Online (Sandbox Code Playgroud)

一个简单的案例:

ex1 = np.arange(9).reshape(3, 3)
ex2 = ex1.copy()
ex3 = ex1.copy()
Run Code Online (Sandbox Code Playgroud)

收益:

>>> example1(ex1)
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

>>> example2(ex2)
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

>>> example3(ex3)
array([[1, 2, 3],
       [4, 5, 6], …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

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

python赋值给循环中的元素列表

这是一个有效的python行为吗?我认为最终结果应该是[0,0,0]并且id()函数应该在每次迭代时返回相同的值.如何使它成为pythonic,而不是使用枚举或范围(len(bar))?

bar = [1,2,3]
print bar
for foo in bar:
    print id (foo)
    foo=0
    print id(foo)
print bar
Run Code Online (Sandbox Code Playgroud)

输出:

[1, 2, 3]
5169664
5169676
5169652
5169676
5169640
5169676
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

python loops list object instance

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

标签 统计

python ×4

list ×2

arrays ×1

instance ×1

loops ×1

numpy ×1

object ×1

operators ×1

pascal ×1

python-3.x ×1

tuples ×1