카테고리 없음

221228

Berylly 2022. 12. 28. 17:32

T. 김동식 + 서치보완

 

상속 extends 확장하다

하위클래스 호출시, 상위클래스가 호출된 이후 상속받은 하위클래스가 호출된다

 

this 와 super = 부모의 멤버변수 과 생성자(부모)

기본값 'super() 부모생성자' 은 생략되어있다.

public Customer(int customerID, String customerName) {
		super(); //	object, 최상위 클래스.
		this.customerID = customerID;
}
//	고객정보
	String showCustomerInfo(){
		return customerName + "님의 등급은 " + customerGrade + "이고, 보너스 포인트는 "+bonusPoint+"입니다"; 
	}

//	고객정보
	String showCustomerInfo(){
		return super.showCustomerInfo()+", 담당직원 "+agentID+"이 연락드릴겁니다."; 
	}

 

 

Class 형변환

VIPCustomer는 VIPCustomer 타입이면서 Customer타입

반대는 오류, 불가하다,  집합을 상상하라.

Customer kim = new VIPCustomer(10010, "박상희", 0314);
// VIPCustomer kim = new Customer(10010, "박상희", 0314);

 

 

 

@Override annotation 

컴파일 주석기호

재정의, 부모의 말을 거역하다로 이해하라.

@Override
String showInfo() {
	return super.showInfo()+", 전문상담원 "+manage+"이 연락드릴겁니다. 누적결제액: "+(int)(price-(price*discount));
}

 

 

 

Python

 

time.sleep(n) 

n초 있다가 출력하라

import time

for i in range(10,1-1,-1):
    time.sleep(1)
    print(i)
print("폭파!!!!!!!!!!!")

 

+

문제를 풀다가 한글추출이 어려워서 서치하다가 가~힣 범위로 코딩한 분을 발견했다.

보완해 첫 시작을 ㄱ으로 변경했다.

str1 = input()
strLen = len(list(str1))
ord(str1[0])

totA = 0;
tota = 0;
totk = 0;
tot0 = 0;
tote = 0;

# 테스트
for i in range(strLen):
    if chr(ord(str1[i])) >= 'A' and chr(ord(str1[i]))<='Z':
        totA +=1
    elif chr(ord(str1[i])) >= 'a' and chr(ord(str1[i]))<='z':
        tota +=1
    elif chr(ord(str1[i])) >= '0' and chr(ord(str1[i]))<='9':
        tot0 +=1
    elif chr(ord(str1[i])) >= 'ㄱ' and chr(ord(str1[i]))<='힣':
        totk +=1
    else:
        tote +=1
          
print("대문자", totA ,"개");
print("소문자", tota ,"개"); 
print("숫자", tot0 ,"개");     
print("한글", totk ,"개");
print("기타", tote ,"개");

 

 

dict와 set(집합)

print(type({1:1,2:2}))
print(type({1, 2}))

<class 'dict'>
<class 'set'>

 

 

set(집합)

집합은 중복/순서가 없다.

for i in set([1, 2, 2,  3, 3, 3, 4, 5]):
    print(i, end="")
    
[출력결과]
12345
se1={3, 3, 1, 2, 9, 6, 3, 53}
print(se1[0])

[출력결과]
TypeError: 'set' object is not subscriptable

 

list combination

 

# 예시

[i/2 for i in [1, 2, 3, 4, 5]]
[0.5, 1.0, 1.5, 2.0, 2.5]

[i for i in [1, 2, 3, 4] if i%2 ==0]
[2, 4]

[i for i in range(1, 10+1) if i > 0]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

 

upper, lower, swapcase, title

myStr = "Hello hello"
print(myStr.upper())
print(myStr.lower())
print(myStr.swapcase())
print(myStr.title())

[출력결과]
HELLO HELLO
hello hello
hELLO HELLO
Hello Hello

 

 

문자열 함수 join, replace, split

ss='Python'
'-'.join(ss) 

[출력결과]
'P-y-t-h-o-n'
ss.replace('n','!')

[출력결과]
'Pytho!'
ss = 'Py! tho: ,n'
strings1 = text.split()
print(strings1)

strings2 = text.split(',')
print(strings2)

strings3 = text.split(':')
print(strings3)

strings4 = text.split('!')
print(strings4)

[출력결과]
['Py!', 'tho:', ',n']
['Py! tho: ', 'n']
['Py! tho', ' ,n']
['Py', ' tho: ,n']

 

 

 

count, find, rindex, startswith

myStr = 'Hanbit Media, Hanbit Academy, Hanbit Life'
myStr.count('Hanbit')
myStr.find('Hanbit', 2) #2번째 Hanbit의 숫자를 구하라 14
myStr.rindex('Media')# 마지막 Media의 위치 7
myStr.startswith('Hanbit')#Hanbit으로 시작하는지 여부 true

 

 

 

isdigit() 숫자여부파악

str = "IT CookBook 1234 파이썬"
out = ""

for i in str:
    if i.isdigit() == False:
        out += i;
print(out)  

[출력결과]
IT CookBook  파이썬