社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

quamrana

quamrana 最近创建的主题
quamrana 最近回复了

你可以用 zip() cycle() :

from itertools import cycle

A = ['A','B','C','D','E','F','G','H']
B = ['a', 'b']

C = [a + b for a,b in zip(A, cycle(B))]
print(C)

按要求输出。

3 年前
回复了 quamrana 创建的主题 » 我被python中的变量困住了

我的方法是将位置移动到程序的顶部:

random_locations = [(100, 440), (350, 440), (600, 440), (100, 260), (350, 260), (600, 260), (100, 80), (350, 80), (600, 80)]
test_sucks = None

if pygame.Rect.colliderect(hammer_rect, mole_rect):
    randomsucks = random.choice(random_locations)
    while randomsucks == test_sucks:
        randomsucks = random.choice(random_locations)
    test_sucks = randomsucks
    ...
    # use randomsucks
3 年前
回复了 quamrana 创建的主题 » 你知道如何在python中输入来自同一类的对象吗?

你只需要访问 _x _y 属性:

import math

class Point:

        def __init__(self, x=0, y=0):
            self._x= x
            self._y= y

        def distanceFromOther(self, b):
            x = b._x
            y = b._y
    
            otResult = math.sqrt(math.pow(self._x-x,2) + math.pow(self._y-x,2))
            return otResult

        def __str__(self):
            return f"({self._x}, {self._y})"

此外,您不需要将方法的参数转换为该对象的属性。

5 年前
回复了 quamrana 创建的主题 » 在下面的问题中使用了python代码

您可以利用列表的索引 lis[-1] 环绕以访问最后一个元素。

此函数在末尾添加一个额外的非活动单元格,以使列表末尾的相邻单元格检查正常。

def cellCompete(c, d):
    c = c[:]
    for _ in range(d):
        q = [0] * len(c)
        c.append(0)
        for index in range(len(q)):
            next_state = 0 if c[index - 1] == c[index + 1] else 1
            q[index] = next_state

        c = q
    return c

作为两个测试用例输出。