• 회원가입
  • 로그인
  • 구글아이디로 로그인

[module] Python - random.shuffle() 메서드 ★★ - 요소 순서 뒤섞기. (= 순서 랜덤 = shuffle메서드 = 셔플)

5186  
목차
  1. random.shuffle() 예제 - 순서 뒤섞기
  2. random.shuffle() 정의
  3. random.shuffle() 구문
  4. random.shuffle() 예제 - shuffle 1회 후 순서 고정

 

random.shuffle() 예제 - 순서 뒤섞기

 

import random

code = ["HTML", "CSS", "JS"]

random.shuffle(code)

print(code)


결과값 예: 순서 랜덤의 List
['HTML', 'JS', 'CSS']

 

random.shuffle() 정의

 

시퀀스 순서 뒤섞기. (= 순서 랜덤 배치)

   

※ 시퀀스 : String, List, Tuple 등.

원본이 바뀜. (※ 복사본 생성 후 변환 X)

※ Python 3.9부터 function 매개변수 제거.

 

 

random.shuffle() 구문

 

random.shuffle(sequence)

 


[매개변수]

 

sequence

필수. 시퀀스. (예: String, List, Tuple 등.) 

 


PA.

function 매개변수는 Python 3.9부터 제거됨.

function

선택. 숫자 0.0 ~ 1.0 사이  값 반환하는 함수 이름.

※ 지정 안 된 경우, random.random() 메서드 사용.

 

 

random.shuffle() 예제 - shuffle 1회 후 순서 고정

※ Python 3.9부터는 사용 불가한 방식임.

 

import random

def hz():

  return 0.1

code = ["HTML", "CSS", "JS"]

random.shuffle(code, hz)

print(code)

 

결과값 예: ["CSS", "JS", "HTML"]



분류 제목
module Python - math.exp() 메서드 -
module Python - math.expm1() 메서드 -
module Python - math.fabs() 메서드 -
module Python - math.factorial() 메서드 -
module Python - math.floor() 메서드 ★ - 바닥 반올림 (= 하위 정수로 반올림. = floor메…
module Python - math.fmod() 메서드 -
module Python - math.frexp() 메서드 -
module Python - math.fsum() 메서드 -
module Python - math.gamma() 메서드 -
module Python - math.gcd() 메서드 -
module Python - math.hypot() 메서드 -
module Python - math.isclose() 메서드 -
module Python - math.isfinite() 메서드 - 숫자 유한 여부 체크 (= math.isfinite메…
module Python - math.isinf() 메서드 -
module Python - math.isnan() 메서드 ★ - NaN 여부 체크. (= isnan메서드 = 이즈난메서…
module Python - math.isqrt() 메서드 -
module Python - math.ldexp() 메서드 -
module Python - math.lgamma() 메서드 -
module Python - math.log() 메서드 -
module Python - math.log10() 메서드 -
4/7
목록
찾아주셔서 감사합니다. Since 2012