본문 바로가기

_Programming/Python

(11)
Basic.입출력 # 표준 입출력 print("Python", "Java", sep=",") print("Python", "Java", "Javascript", sep=" vs ") # Python vs Java vs Javascript print("Python", "Java", sep=" , ", end="?") # 뒷 줄이 이어서 출력됌. print("무엇이 더 재밌을까요?") # Python , Java?무엇이 더 재밌을까요? import sys print("Python", "Java", file=sys.stdout) # 표준출력으로 문장이 찍힘. print("Python", "Java", file=sys.stderr) # 표준에러로 처리됌. score = {"수학":0, "영어":50, "코딩":100} for s..
Basic.함수 # 함수 (들여씌기 내어쓰기 조심) def open_account(): print("새로운 계좌가 생성되었습니다.") open_account() # 전달값과 반환값 def deposit(balance, money): #입금 print("입금이 완료되었습니다. 잔액은 {0}입니다.".format(balance + money)) return balance + money def withdraw(balance, money): # 출금 if balance >= money: print("출금이 완료되었습니다. 잔액은{0}입니다.".format(balance - money)) return balance - money else: print("출금이 완료되지 않았습니다. 잔액은 {0}입니다.".format(balance..
Basic.제어문 # if : 분기 weather = "맑음" if weather == "비": print("우산을 챙기세요") elif weather == "미세먼지": print("마스크를 챙기세요") else: print("그냥 터덜터덜 나가세요") # input : 우리의 대답을 기다림. weather = input("오늘 날씨는 어때요?") if weather == "비" or weather == "눈": print("우산을 챙기세요") elif weather == "미세먼지": print("마스크를 챙기세요") else: print("그냥 터덜터덜 나가세요") temp = int(input("기온은 어때요?")) if 30
Basic.자료구조 # 리스트 [] : 순서를 가지는 객체의 집합 # 지하철 칸별로 10명, 20명, 30명 subway1 = 10 subway2 = 20 subway3 = 30 subway = [10, 20, 30] print(subway) subway = ["정맥주", "고감자", "박사탕"] # 고감자는 몇번째 칸에 타고 있는가? print(subway.index("고감자")) # 정불닭이 다음 정류장에 다음 칸에 탐. subway.append("정불닭") print(subway) # 서버섯이 정맥주와 고감자 사이에 탐. subway.insert(1, "서버섯") print(subway) # 지하철에 있는 사람을 한 명씩 뒤에서 꺼냄 subway.pop() print(subway) subway.pop() print(s..