전체 글
-
라즈베리파이 : 파이썬 연습문제 (클래스,객체,인스턴스)카테고리 없음 2023. 2. 27. 12:33
1 _ 번 : 클래스, 객체, 인스턴스의 정의 2 _ 번 : 기본 생성자( __init__ ) 생성 - 기본 생성자에 print 명령어를 추가해서 객체를 생성하는 것으로 문자열이 출력되게 만들었다. 3 _ 번 : argument를 받는 생성자 - self 키워드를 이용해서 객체 생성 시 이름,나이,성별 attributes를 저장하도록 만들었다. 4 _ 번 : arguments를 받는 생성자 사용하기 - 받은 arguments를 객체를 생성할 때 출력되도록 작성했다. 5 _ 번 : who() 메소드를 추가해서 출력하기 - areum 으로 Human클래스의 객체를 arguments를 넣어 생성하고 attributes에 arguments를 저장시킨 후 areum.who() 메소드로 저장되 있던 값들을 형식에 ..
-
Nomard) html,css,script 기초(1)기타 2023. 2. 25. 20:09
// 변수 const vari = 1; //배열 const arr = [a , b , c]; arr[1] = g; // const 지만 배열 내부 값은 변경 가능 배열에 요소를 추가하는 방법 arr.push(값) // 객체 const objec = { name: "me", points: 10, boolean1 : true sayHello: function(){} // 객체 내부에 함수 선언 방법 }; // 객체 호출 방법 2가지 console.log(player.name) console.log(player["name"]); objec.sayHello(); ** const는 수정이 불가능한 타입의 선언이지만 const objec 내부의 정보를 수정하는 것은 가능하다 ( objec 자체를 수정하는 것은 불가..
-
Ch03. 파이썬 기초 (함수, 클래스, 모듈)Raspberry Pi ( python ) 2023. 2. 24. 12:07
1 _ 함수 : 함수 선언의 기본적인 형태는 다음과 같다. def 함수명( ):# 인수 없는 함수 실행문 def 함수명( 인수 ):# 인수 있는 함수 실행문 예제) 함수 선언 - def mydef02(str="인수함수를 선언합니다."): 파이썬의 특징으로 매개변수를 선언하면서 값을 저장할 수 있다. 예제) 함수 인수 사용하기 2 _ 클래스 : 클래스는 프로그래밍 과정에서 객체를 정의하는 데이터와 이를 활용하는 기능을 가질 수 있는 구조이다. 각 클래스는 객체의 상태를 정의할 수 있는 속성(attributes)과 객체의 기능을 정의하는 메서드(methods)를 가질 수 있는 구조이다. class 클래스명:#클래스 선언 name = "" velocity = 0# 숫자, 문자 등의 객체 선언 def 함수명( ..
-
Ch03. 파이썬 기초 (제어문)Raspberry Pi ( python ) 2023. 2. 24. 11:14
1 _ if 문 : 다른 프로그램과 기능적으로 큰 차이는 없다. if , else , elif 문 3개가 있다. 기본 형태 if 조건: 실행문 else: 실행문 if 조건: 실행문 elif 조건: 실행문 else: 실행문 예제) 2 _ for 문 : 특정 코드를 지정 횟수만큼 반복하는 문장 for 변수 in range( 시작 값 , 조건값(원하는 종료값+1) , 증감값 ): 실행문 예제) - for 문을 선언할 때 처리할 목록은 리스트, 튜플, 문자열이 가능하고 이 변수들의 첫 요소부터 마지막 요소까지 변수에 대입되어 반복이 됩니다. 예제) 다양하게 for 문을 활용해보자 - print( ) 내부에 end="" 는 기본적으로 적용되어있는 print() 문의 개행을 없에고 print문이 출력이 끝난 지점에..
-
라즈베리파이 : 파이썬 연습문제 (02/23)Raspberry Pi ( python ) 2023. 2. 23. 16:48
02/23 1) # 1) type() 함수를 이용하여 아래 변수에 바인딩된 값의 타입을 판별해보세요. a = "132" print(type(a)) # 2) 변수 s 와 t에는 각각 문자열이 바인딩 되어있습니다. s = "hello" t = "python" # 두 변수를 이용하여 아래와 같이 출력 해보세요. print(s+"! "+t) print(s+"!",t) # 두 실행문은 같은 결과가 나온다 ( , = space 바) # 3) 아래 코드의 실행 결과를 예상해보세요. a = "3" b = "4" print(a + b) print("Hi" * 3) # 4) 화면에 '-'를 80개 출력하세요. print("-"*80) # 5) 변수에 다음과 같은 문자열이 바인딩되어 있습니다. t1 = 'python' t2..
-
Ch03. 라즈베리 파이를 위한 파이썬 기초Raspberry Pi ( python ) 2023. 2. 23. 16:31
01 _ 파이썬 : 빅 데이터 등의 통계, 함수와 관련된 코드를 만들기 좋은 프로그램이다. java나 javascript 와는 중괄호 개념이 다르고, 들여쓰기 규칙을 사용한다. Tab 키 사용을 지양하도록 하자. 예시) if 문을 사용한다면. def factorial(x): if x = 0: 참에 대한 결과1 참에 대한 결과2 else: 거짓에 대한 결과1 거짓에 대한 결과2 주석 # 한 줄 주석 ''' 여러 줄 주석 ''' """ 여러 줄 주석 """ print('주석 예제입니다.'); 02 _ 파이썬 자료형 1. 숫자형 : 정수 및 실수를 표현하는 타입. 타입을 키워드로 구분하지 않는다 a = 123 print(type(a))#type 함수는 변수의 타입을 리턴 a = 100 * 100 print(a..
-
혼공자 : ch10 예외처리Java 2023. 2. 23. 11:02
10-2 예외처리 예외 : 사용자 조작 실수, 개발자 코딩 문제 발생 오류 예외가 발생하면 프로그램 종료. > 정상 실행 상태 유지를 위해 예외처리 예외 처리 코드 예외 처리 코드 : try - catch - finally 블록 try 블록에는 예외 발생 가능 코드가 위치한다. try 블록의 코드가 예외 발생 없이 정상 실행되면 catch() 블록의 코드를 스킵하고 finally 블록의 코드를 실행한다. 만약 try 블록에서 예외가 발생하면 즉시 실행을 멈추고 catch() 블록으로 이동하여 예외 처리 코드를 실행한다. 그리고 finally 블록의 코드를 실행한다. finally 블록은 생략 가능하며, 예외 발생 여부와 상관없이 항상 실행할 내용이 있을 경우에만 finally 블록을 작성해준다. 심지어 ..