Python/Python Basic

03. 데이터 타입

HicKee 2023. 1. 11. 23:47
# 데이터 타입
# 산술 연산자 (+, -, *, /, %) C C# 과 동일
# ++, -- 없음

# 비교 연산자 (>, >=, <, <=, ==, !=) C C# 과 동일
# 논리 연산자 (and, or, not) : &&, ||, !
num1, num2 = 100, 200
# num1에 100, num2에 200

print(f"and 논리 연산자 : {(num1>num2) and (num1<num2)}")
print(f"or 논리 연산자 : {(num1>num2) or (num1<num2)}")
# 문자열 indexing
str1 = 'hello python'
str_len = len(str1)
print(f"문자열 길이 : {str_len}")

print(str1[0], str1[6], str1[str_len-1])

# 문자열 내부 검색 (특정 문자 검색)
find_word = 'th'
res = find_word in str1
print(f'{find_word} 단어검색 : {res}')

# 문자열 자르기 (슬라이싱)

# str1[ start index : end index] (start index 포함 end index 미포함)
print(str1[0:2])  # index 0 ~ index 1 까지
print(str1[1:])  # index 1 ~ 끝까지
print(str1[:3])  # 처음부터 index 2까지
print(str1[:-2])  # 처음부터 끝에서 -2 까지

'Python > Python Basic' 카테고리의 다른 글

06. 리스트 List 02  (0) 2023.01.13
05. 리스트 List 01  (0) 2023.01.13
04. 제어문 IF  (0) 2023.01.12
02. IO 입출력  (0) 2023.01.10
01. 파이썬 설치하기  (0) 2023.01.09