CS 101/grammar (12) 썸네일형 리스트형 [Python] 문자열에서 숫자만 추출하기 1. 모든 숫자들을 1개의 문자열로 추출 : re.sub()sub()는 string에서 pattern과 일치하는 문자들을 repl로 교체합니다.re.sub(pattern, repl, string) 다음과 같이 sub()를 사용하여 문자열에서 숫자가 아닌 문자를 모두 제거하고 숫자로 구성된 문자열을 만들 수 있습니다.import restring = 'aaa1234, ^&*2233pp'numbers = re.sub(r'[^0-9]', '', string)print(numbers) Output:123422332.연속된 숫자들을 추출하여 List로 리턴 : re.findall()re.findall(pattern, string)은 string에서 pattern에 해당하는 내용들을 찾아서 리스트로 리턴합니다. r'.. [C/C++] overloading & overriding C++을 배우면서 이 단어들을 들어 보지 못한 사람은 아마 없을 것입니다.단어가 비슷하기 때문에 처음 배우면 개념이 상당히 헷갈리기도 합니다.간단하게 오버로딩과 오버라이딩을 정의해보면 다음과 같습니다.오버로딩은 함수의 중복 정의, 오버라이딩은 함수의 재정의1. 오버로딩(Overloading)오버로딩은 다음과 같습니다.#include using namespace std;void func(int i){ cout 오버로딩을 자세히 정의해 보면 다음과 같습니다.오버로딩은 함수명이 같고 매개 변수의 타입이나 개수가 다른 함수를 허용하는 것이다.즉, 함수명이 같이도 전달받는 인자의 개수나 타입이 다르면 서로 다른 함수로 인식합니다.위의 결과를 보면 분명히 그렇게 출력되고 있음을 알 수 있습니다.만약 저 소스에서 주.. [Java] Overriding & Overloading overloading method의 이름은 같고, 매개변수의 갯수/타입이 다른 함수를 정의하는 것 리턴값만 다른 오버로딩은 불가능 overriding 상위 클래스의 method를 하위 클래스에서 재정의하는것 method의 이름, parameter의 갯수, 타입 동일. 주로 상위클래스의 상속받은 동작을 하위클래스에서 변경하기위해 사용 [Java] Interface Interface는 자신을 구현하는 class들이 반드시 가져야 할 methods들의 heading들을 지정하고 있다. 어떤 인터페이스를 구현하는(implements) 클래스는 반드시 자신이 구현하는 인터페이스에 선언된 모든 메소드를 구현해야 한다. 그렇지 않으면 오류가 발생한다. [Java] Binding early binding Method definition과 method invocation의 연결이 compile time에 일어남 -Early binding objects are basically a strong type objects or static type objects. late binding Method definition과 method invocation의 연결이 그 method가 call 된 순간 일어남 -하나의 method invocation에 여러 의미를 가지게 하는 메카니즘은 polymorphism을 말하며, late binding에 의해 구현될 수 있다. Java(ch5. Defining Class 2)-Static, References,usingMisusingRef,PackagesJavadoc Static can be used without calling obj public class RoundStuff { public static final double PI = 3.14 public static final double area(double radius) { return ( PI * ~~~) } } public class RoundStuffDemo { public static void main(String[] args) { System.out.println( RoundStuff.area(radius) + "square inches."); } static method : -cannot refer to an instance variable of the class -cannot invoke a no.. Java(ch4)-class, information hiding, overloading, constructors class all objects of a class have the same methods and variables but different objects can hold different values in the same variable more about methods 2 types of methods return type (int, string, etc...) void type public class SampleClass{ public int x; public void sayHello(int y) { System.out.println("Hello" + x + " " + y); } public int sqareX() { return x*x ; } } SampleClass c1 = new SampleC.. Java(ch3) - Loops, random numbers while while (Boolean) { statement_1 statement_2 statement_last } Scanner keyboard = new Scanner(System.in); System.out.println("put all your score and end with negative num"); double next, sum = 0; int count = 0; next = keyboard.nextDouble(); while (next >= 0) { sum += next; count ++; next = keyboard.nextDouble(); } if (count == 0) System.out.println("no scoresm entered"); else{ double average =.. 이전 1 2 다음