객체 목록 섞기
문제:
random.shuffle() 함수. 예상되는 순서 섞기 동작이 발생하지 않는 것 같고 함수는 대신 None을 출력합니다.
해결책:
객체 목록을 효과적으로 섞으려면 shuffle( ) 무작위 모듈의 기능은 다음과 같습니다. 다음:
from random import shuffle objects = [obj1, obj2, obj3] # initialize the list of objects shuffle(objects) # shuffle the objects in place
설명:
다른 프로그래밍 언어와 달리 Python에서는 Random.shuffle()이 제자리에서 작동합니다. 새 것을 반환합니다. 또한 객체를 변경하려는 경우 Python의 함수가 None을 반환하는 것이 일반적인 관행입니다.
샘플 코드:
from random import shuffle x = [[i] for i in range(10)] shuffle(x) print(x)
이렇게 하면 목록 x의 목록이 섞입니다. 그리고 섞인 것을 인쇄하세요 result.
참고:
shuffle()은 원래 목록을 변경하므로 후속 작업이나 목록에 대한 액세스는 shuffle에 의한 변경 사항을 반영한다는 점을 기억하는 것이 중요합니다. ().
위 내용은 Python의 `random.shuffle()`이 `None`을 반환하는 이유는 무엇이며 어떻게 올바르게 사용할 수 있습니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

WebStorm Mac 버전
유용한 JavaScript 개발 도구