#문자열str '' "" : 글자(문자)들이 모여서 만들어진 자료형
#문자열 안의 각각의 글자를 원소라 부르며
#문자열은 순서(인덱스)를 가진다
#구성 원소는 같지만 순서가 다르므로 다른 문자열
t1 = '파이썬'
t2 = '썬파이'
print(t1 == t2)
#인덱스는 0부터 시작!!
#인덱싱 : 원소 하나를 가져오는 것
#문자열 인덱싱 : 문자열[인덱스]
t3 = 'Hello'
print(t3[0])
print(t3[3])
print(t3[-1])
#슬라이싱 : 일부를 가져오는 것
#문자열 슬라이싱 : 문자열[start:end] 문자열[start:end:step]
#종료end 인덱스는 포함하지 않는다
t4 = '파이썬은 재미있어요!'
print(t4[0:6])
print(t4[:4])
print(t4[-3:])
print(t4[1:9:])
print(t4[-2:-10:-2])
print(t4[::-1])
print('----문제1----')
text1 = 'Hello! Python'
#Python 출력
print(text1[7:])
#!출력
print(text1[5])
#소문자 h출력
print(text1[-3])
print('----문자열 메서드----')
'''
len( ) : 길이
lower( ) : 모두 소문자
upper( ) : 모두 대문자
replace(a, b) : a를 b로 변경
find(a) : a가 처음 나오는 인덱스 값 출력,
a 값이 없다면 -1 출력
split(a) : a기준으로 나누기
'''
s = "Python is FUN!"
print(len(s)) #길이
print(s.lower()) #소문자로 변환
print(s.upper()) #대문자로 변환
print(s.replace(" ", "-")) #a를 b로 변환
print(s.find("FUN")) #a가 처음 나오는 인덱스 값 출력
print(s.find("in")) # a 값이 없다면 -1 출력
print(s.split()) #구분자 기준 나누기
print('----문제2----')
#이메일 사용자명 추출 프로그램 만들기
#변수로 이메일 주소를 제공하고, @ 앞의 사용자명을 추출함
email = "student123@gmail.com"
#방법1 전부 변수로 나누기
parts = email.split("@")
username = parts[0]
print("사용자명:", username)
#방법2 바로 사용
email = "student123@gmail.com".split("@")
print("사용자명:", email[0])
#변수를 사용하지 않는 방법
print("student123@gmail.com".split("@")[0])
print('----탈출 문자----')
'''
\n : 줄바꿈
\t : 탭
\” or \’ : 따옴표
\\ : \(역슬래시)
'''
print('Pine\nApple')
print("이름\t성적")
print("문자열 안에 따옴표 출력: \"Hello\"")
print("\\안녕하세요\\")
To embed this project on your website, copy the following code and paste it into your website's HTML: