- 파일에서 단어 읽기 infile = open("C:\\Users\\Desktop\\happy.txt", "r") for line in infile: line = line.rstrip() word_list = line.split() for word in word_list: print(word) infile.close() - 파일 복사 infilename = input("기존 파일 이름: ") outfilename = input("복사된 파일 이름: ") infile = open(infilename, "r") outfile = open(outfilename, "w") s = infile.read() outfile.write(s) infile.close() outfile.close() shutil 모듈 사..
입력 - input("~") : 뒤에 커서가 깜빡이고 거기에 값을 입력하면 값이 문자열 형태로 반환 : 항상 문자열 형태로 입력 answer = input("값 입력 : ") # 값 입력 : 5 print(type(answer)) # print("입력하신 값은 " +answer+ "입니다.") # 입력하신 값은 5입니다. sep : 문자열 사이를 어떻게 할 지 결정 print("Python", "Java", sep = ",") # Python,Java print("C", "Java", sep = " vs ") # C vs Java end : 문자열의 끝부분을 어떻게 할지 결정 print("Python", "Java", sep = " vs ", end ="?") print(" 어떤 걸 고를까?") # Py..
1. 변수(variable) 변수란, 단 하나의 값을 저장할 수 있는 메모리 공간 변수 선언 변수타입 변수이름; 변수 초기화 변수타입 변수이름 = 값; // 오른쪽 값이 왼쪽의 변수에 대입 변수 화면에 출력 System.out.println(변수); 두 변수의 값 교환(swap) public class Swap { public static void main(String[] args) { int x = 10, y = 20, tmp; System.out.println("x:" + x + " y:" + y); // x:10 y:20 tmp = x; x = y; y = tmp; System.out.println("x:" +x + " y:" + y); // x:20 y:10 } } ※ 덧셈연산자(+)는 두 값을 ..