[python] 난수 생성하기 random의 모든 것
random 모듈을 이용하여 난수 생성하기 module importimport random random.random( )# 0이상 1미만의 실수random.random()→ 0.28483 random.randrange( start , stop [ , step] ) *정수만 생성# 1이상 7미만의 정수random.randrange(1, 7) # 1이상 10미만, 간격 2random.randrange(1, 10, 2)→ [1, 3, 5, 7, 9] 중 하나 random.randint( Start, End )# start 이상 end 이하의 정수 생성random.randint( 1, 3 )→ 1~3 중 하나 random.uniform( a, b ) *실수 생성# 1이상 2이하 실수 생성rand..
2024. 9. 22.
[python] 파이썬 클래스 개념 (__init__, self)
클래스 (Class): 동작(behavior, method, function)과 상태(state, attribute, variable)의 묶음 → 객체를 찍어내기 위한 설계도 클래스 만들기# 클래스class Person : def setdata(self, name, age): self.name = name self.age = age # 객체 생성 p1 = Person() p1.setdata('spectrum',20) 클래스에 메소드 추가하기class Person : def setdata(self, name, age): self.name = name self.age = age def walk(self): print('뚜벅뚜벅') def talk(self)..
2024. 5. 19.