숫자형 자료형
- 기본적인 숫자 연산이 가능(덧셈, 뺄셈, 곱셈, 나눈셈, 몫, 나머지)
- 지수표현 가능 3.14E10, 3.14E-10
문자형 자료형
- 문자를 표현하는 자료형
- 문자열끼리 덧셈은 붙여주는 역할을 함
- 문자열 자료형은 꼭 처음과 끝에 작은 따옴표 or 큰 따옴표를 붙여줘야함
- 엔터나 탭키도 모두 문자이므로 유의하기
지수표현
a = 5.15E + 10 = 5.15 x 10의 10승
a = 5.15E - 10 = 5.15 x 10의 -10승
나눈 후 나머지 값 구하기
a = 3
b= 5
print(a % b)
= 3
나눈 후 몫 값 구하기
a = 3
b= 5
print(a//5)
= 0
이스케이프 코드 : 미리 정의 둔 문자조합

문자열 슬라이싱
print(a[2:9]) = 2 ~ 9전까지
print(a[:9]) = 0번째 부터 9전까지
print(a[3:]) = 3번째부터 끝까지
문자열뒤에 . 찍고 함수이름 적어준다.
text = " I eat { } apples.format(3)
text = " I eat {0} apples and {0} oranges".format(3,5)
text = "[:>10]".format("Hi")
print(text) => "(빈공간10칸)Hi"
:>10 = 열개의 공간정렬
:<10 = 뒤로 열개의 공간정렬
:^10 = 양쪽공간 5개씩
:=^10 = 반공간을 ===문자로 채움
:.2ㄹ = 소수점 2자리까지만 표현
text = "Python:is:too:fun!"
print(text.count('o'))
=> 3
text = "Python is too fun!"
print(text.find("o"))
=> 4
print(text.find("z"))
=> -1 (없으면 -1로 나옴)
text = ','.join("abcde")
print(text)
=> a,b,c,d,e
text = "Python"
print(text.upper())
=> "PYTHON"
text = "PYTHON"
print(text.lower())
=> "python"
text = " (공백) Hello(공백) "
print(text.lstrip())
=> "Hello (공백)"
text = "(공백) Hello (공백)"
print(text.rstrip())
=> "(공백)Hello"
text = "(공백) Hello (공백)"
print(text.strip())
=> "Hello"
text = "Python is too fun!"
print(text.replace("Python", "Java")
=> "Java is too fun!"
text = "Python is too fun!"
print(text.split())
=> ['Python','is','too','fun!']
(리스트로 나온다)<br>
text = "Python:is:too:fun!"
print(text.split(':'))
=> ['Python', 'is', 'too', 'fun!']
(':' 콜론을 넣으면 콜론 기준으로 잘라준다)
text = "Python is too fun!"
text.startswith("Python")
=> True
<br>
text.startswith("is")
=> False
text = "Python is too fun!"
text.endswith("fun!")
=> True
text.endswith("is")
=> False
text="Hello"
print(text.isalpha())
=> True
text="Hello World99!"
print(text.isalpha())
=> False (공백이나 숫자가 있으면 False)
text = "300"
print(text.isdigit())
=> True
text = 'hello300'
print(text.isalnum())
=> True
text = ' '
print(isspace())
=> True
text = "Hello"
print('Hello'.swapcase())
=> "hELLO"