Integer numbers (정수)
- 0, 1, 2, 10, 11, 100, ...
- Underscore (
_
) 도 쓸 수 있다.- underscore (
_
) 갯수는 상관 없다. 1000000
=1_000_000
=1__000___000
(O)1_2_3
(O)_10
,100_
(X)
- underscore (
if(123 === 1_2_3) {
print("SAME")
}
else {
print("DIFFERENT")
}
// SAME 출력
Characters (문자)
- 단일 문자 (sigle character) 를 쓸 때 사용한다. 숫자, 글자 등을 쓸 수 있다.
'
로 감싼다.'A'
,'B'
,'C'
,'0'
,'9'
- 여러개의 문자를 쓸 수 없다.
'A'
(O)'abc'
,543
(X)
if('123' === 123) {
print("SAME")
} else {
print("DIFFERENT")
}
// 실행할 수 없는 코드이다
// 왜냐하면 Kotlin 은 서로 다른 타입끼리 비교할 수 없기 때문이다
Strings (문자열)
- 문자열은 character (문자) 의 sequence 이다. 즉 여러개의 문자를 쓸 수 있다.
"
로 감싼다."text"
,"I want to learn Kotlin"
,"123456"
,"e-mail@gmail.com"
- 문자를 하나를 쓴다고 해서 character 가 되지 않는다.
"A"
는 String 이고,'A'
는 Character 이다.
if(A_String === A_Char) {
print("SAME")
} else {
print("DIFFERENT")
}
// 실행할 수 없는 코드이다
// 왜냐하면 Kotlin 은 서로 다른 타입끼리 비교할 수 없기 때문이다
정리
123
은 Integer number 이고,"123"
은 String 이다.'123'
은 불가능하다.1
은 Integer number 이고,"1"
은 String 이다.'1'
은 Character 이다.'A'
는 Character 이고,"A"
는 String 이다.
참고자료
https://hyperskill.org/learn/step/4350
Introduction to Kotlin – JetBrains Academy — Learn programming by building your own apps
What is Kotlin? Kotlin is a highly effective modern programming language developed by JetBrains. It has a very clear and concise syntax, which makes your code easy to read. Kotlin is widely used around the world, and its popularity among developers is cons
hyperskill.org
'코틀린 Kotlin' 카테고리의 다른 글
변수 (0) | 2023.02.03 |
---|---|
프로그램 (Program) 용어 및 톺아보기 (0) | 2023.02.03 |
코틀린 이란 (0) | 2023.02.03 |