小编use*_*772的帖子

和python中的操作重载

我知道逻辑上and用于布尔值,如果两个条件都为真,则评估为true,但是我对以下语句有疑问:

print "ashish" and "sahil"

it prints out "sahil"?
 another example:
 return s[0] == s[-1] and checker(s[1:-1])
 (taken from recursive function for palindrome string
 checking            
please explain it and other ways and is oveloaded ,especially what the second statement do.
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
2
解决办法
133
查看次数

没有足够的论据?

print "%r"
Run Code Online (Sandbox Code Playgroud)

VS

print "%r %r"%("hello")
Run Code Online (Sandbox Code Playgroud)

我想在python中比较上面的两行代码.后面的语句给出了一个错误,没有足够的争论打印但是在第一种情况下我们没有争论但仍然有效.任何人都可以向那些不熟悉编程的人解释这一点.任何帮助将不胜感激.

python

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

读取指针声明

# include <stdio.h>
# include <stdlib.h>    
int main(int argc, char *argv[])
{
    int daytab[2][13];
    int (*daytab)[13];
    int *px;

    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

我正在学习指针并且难以阅读int (*daytab)[13]宣言. int *px读取为px指向a的指针int.

你怎么读int (*daytab)[13]

c

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

在C中寻址

#include<stdio.h>
#include<stdlib.h>   
int main(int argc, char *argv[])
{
    int x = 2;
    int *pointer2 = &x;
    int number = &x;
    printf("%x\n",number );
    printf("%x\n",number+1 );
    printf("%x\n",pointer2 );
    printf("%x\n",pointer2+1);

    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

我从gcc得到一个警告,"初始化从指针生成整数,没有强制转换[默认情况下启用]",但是当我编译时,得到以下输出:

5da24540
5da24541
5da24540
5da24544
Run Code Online (Sandbox Code Playgroud)

很明显,上面的事情没有发生,因为我们可以在输出的前两行看到地址只增加1而第二种情况下增加4.请解释并返回可以分配给其他变量的地址,如int或它是一个自我指针,只能指定给指针类型.

c

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

在C中修改函数中的数组

#include <stdio.h>
#include <stdlib.h>

void array_tester(int *array);

int main(int argc,char *argv[])
{   
    int test[] = {1,1,1,1};
    int print;
    for(print = 0; print < sizeof(test) / sizeof(int); print++)
    {
        printf("%d\n",test[print] );
    }

    array_tester(test);
    for(print = 0;print < sizeof(test)/sizeof(int);print++)
    {
        printf("%d\n",test[print] );
    }

    return EXIT_SUCCESS;
}


void array_tester(int array[])
{   
    int i ;
    for(i = 0; i < sizeof(array) / sizeof(int); i++)
    {
        array[i] = i;
    } 
}
Run Code Online (Sandbox Code Playgroud)

问题是我想修改array_tester函数中的数组但我无法这样做.我在里面用sizeof()什么?

c

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

是时候找到链接列表中的最大元素了

我有一个有序的链表.我想知道在两种情况下找到max元素的时间:

  • 如果我保持指向链表末尾的尾指针,和
  • 如果我不这样做.

search linked-list time-complexity data-structures

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

返回列表元素和索引

我试图使用用户制作的功能打印列表的所有元素.

y = [1,2,3]
def ash(list1):
for x in range(len(list)):
    return list[x],x
Run Code Online (Sandbox Code Playgroud)

我想要做的是返回列表中的所有值及其索引,但我得到的只是一个元素.我可以得到要打印但不返回的元素.

python

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

不可调用的字符串对象

def power(num,div):
    incre =0 
    while(num%div == 0):
        num = num/div
        incre +=1
    return incre
test_case = int(raw_input())

lim = 0

while lim  < test_case:
    power = (raw_input())
    x = power.split()
    a = int(x[0])
    b = int(x[1])
    lim +=1
print power(a,b)
Run Code Online (Sandbox Code Playgroud)

Python曾经正常工作,直到我遇到此错误.

python string typeerror python-2.7

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

Python继续与while

在Python中继续似乎存在一些严重的问题:例如:

for i  in range(1,10):
    if i % 2 == 0:
         continue
     print i
Run Code Online (Sandbox Code Playgroud)

按预期工作,但是

i = 0

while(i < 10):
    if i %2 == 0:   
        continue
    i += 1
    print i
Run Code Online (Sandbox Code Playgroud)

while循环永远不会终止!

python loops

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