Programming(72)
-
Golang slice, map, struct
slice slice 선언 s := make([]int, 5, 10) 현재 길이: 5 내부적 길이(capacity) 10의 크기 s := make([]int, 0, 5) 현재 길이: 0 내부 길이: 5 (할당 길이) slice 추가 nodes := make([]*ListNode, 0, 10) chunk_nodes := make([]*ListNode, 0, 10) var node *ListNode node = new(ListNode) chunk_nodes = append(chunk_nodes, node) nodes = append(nodes, chunk_nodes...) ListNode를 pointer로 선언하여 할당 node에 대한 list인 chunk_nodes를 선언 chunk_nodes에 node ..
2021.11.09 -
Golang 기본 문법
1. 변수 1.1 변수 선언 var a int var f float32 = 11. a = 10 f = 12.0사용되지 않는 변수는 error가 발생한다. 아래와 같이 선언만 하고 사용하는 코드가 작성되지 않는다면 error가 발생한다. var i, j, k int = 1, 2, 3:=로 변수의 선언과 할당을 동시에 수행 할 수도 있다. val := 101.2. 상수 var 대신 const를 사용하여 변수를 선언하면 '상수'로서 선언된다. C++의 const와 동일한 keyword를 사용한다. (Kotlin의 경우 val keyword) const c int = 10 const s string = "Hi"Go는 type deduction을 지원한다. 변수 명 뒤에 변수의 type을 지정하지 ..
2021.11.09 -
Golang introduction 2021.11.09
-
gdbus] method 등록 및 호출
gdbus call 1) registration a. generate gdbus wrapping code ex. com.test.module1.xml gdbus-codegen --generate-c-code testbus --c-namespace TestBus --interface-prefix com.test. com.test.module1.xml -> testbus.c/h b. build FLAGS=$(shell pkg-config --libs --cflags gio-2.0 gio-unix-2.0 glib-2.0) server: server.o testbus.o gcc -o $@ $^ $(FLAGS) client: client.o testbus.o gcc -o $@ $^ $(FLAGS) gcc -o t..
2021.09.27 -
[Python] dictionary 응용
dictionary에 key만 추가 : default는 추가만 가능하며 update는 불가능 함 (update는 추가, 수정이 모두 가능함) >>> x = {'a':10, 'b':20} >>> x.setdefault('e') >>> e >>> x {'a': 10, 'b': 20, 'e': None} >>> x.setdefault('f', 100) 100 >>> x {'a': 10, 'b': 20, 'e': None, 'f': 100} 값 수정 1) key에 값 대입 >>> x.update(e=50) >>> x {'a': 10, 'b': 20, 'e': 50, 'f': 100} >>> x.update(a=900, f=60) >>> x {'a': 900, 'b': 20, 'e': 50, 'f': 60} 2)..
2021.09.27 -
[Python] #2 변수와 입력 사용하기
변수는 숫자 및 특수문자를 사용해서 시작할 수 없음 >>> x = 10 >>> x 10 >>> type(x) >>> x, y, z = 10, 20, 30 >>> x 10 >>> y 20 >>> x = y = z =10 변수 삭제 >>> del(x) >>> x … NameError: name ‘x’ is not defined 빈 변수 >>> x = None >>> print(x) None >>> x 출력 없음 None은 다른 언어에서의 null임 >>> x = -10 >>> +x -10 >>> -x 10 key 입력 받기 >>> input() 여기서 입력 가능 >>> x = input() 여기서 입력 >>> x 입력한 내용 출력 >>> x = input(‘입력하세요: ‘) … 입력 값을 정수로 변환 >>>..
2021.09.27