본문 바로가기

Python31

[Python] 프로세스, 스레드 조작 * 부모 프로세스, 자식 프로세스 관계 PID로 확인123456789101112from multiprocessing import Processimport os def foo():    print('foo: child process: ', os.getpid())    print('foo: parent process: ', os.getppid()) if __name__ == '__main__':    print('parent process', os.getpid())    child1 = Process(target=foo).start()    child2 = Process(target=foo).start()    child3 = Process(target=foo).start()  * 멀티 프로세스 구현1234.. 2025. 3. 14.
[Q] Frontend / Backend 컴파일러 언어는 기계 친화적이고 인터프리터 언어는 사용자 친화적이다. 인터프리터 언어로 개발을 하면 상대적으로 속도감있게 개발할 수 있지만, 프로그램 실행 속도가 빠른건 아니다.   codesandbox.io/templates https://codesandbox.io/templates codesandbox.io 2025. 3. 3.
[Python] 패스워드 생성기 123456789101112131415import random def getPass():    alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"    password = ""     for i in range(6):        index = random.randrange(len(alphabet))        password = password + alphabet[index]     return password print(getPass())print(getPass())print(getPass())Colored by Color Scripter 2021. 3. 2.
[Python] 문자열 역순 출력 - reverse_sentence 123456sentence = "I Love You"reverse_sentence = ' 'for char in sentence:    reverse_sentence = char + reverse_sentenceprint(reverse_sentence) Colored by Color Scripter 2021. 3. 2.
[Python] 큰 수의 법칙 다양한 수로 이루어진 배열이 있을 때 주어진 수들을 M번 더하여 가장 큰 수 를 만드는 법칙단, 배열의 특정한 인덱스(번호)에 해당하는 수가 연속해서 K번을 초과하여 더해질 수 없다.     서로 다른 인덱스에 해당하는 수가 같은 경우에도 서로 다른 것으로 간주한다.  (해결방법)1. 입력 값 중에서 가장 큰 수와 두 번째로 큰 수만 저장한다.2. 연속으로 더할 수 있는 횟수는 최대 K번이므로   '가장 큰 수를 K번 더하고 두번째로 큰 수를 한 번 더하는 연산'을 반복한다. 123456789101112131415161718192021222324# N, M, K를 공백으로 구분하여 입력받기n, m, k = map(int, input().split()) # n개의 수를 공백으로 구분하여 입력받기data =.. 2021. 3. 2.
[Python] 거스름돈 계산 12345678910m = 1260  #돈count = 0 #동전 갯수 coin_types = [500, 100, 50, 10] for coin in coin_types:    count += m // coin    m %= coin print('동전 갯수:',count) 2021. 3. 2.
[Python] 수행시간 측정 코드 - time.time() 12345678910import time start_time = time.time() #측정 시작 '''프로그램 소스코드''' end_time = time.time() #측정 종료print("time: ", end_time - start_time) #수행 시간 출력 2021. 3. 2.