Notice
Recent Comments
Link
Tags
- c file read
- ubuntu node js install
- C언어
- tzselect
- 클라우드서버 생성
- 자바 한줄씩 읽기
- 디지털오션 서버생성하기
- Ubuntu timezone
- 라즈베리파이4
- c언어 파일 읽기
- node js 버전확인
- ubuntu node js
- npm버전확인
- mysql index 생성
- raspi-config
- 우분투 node js 설치
- java 숫자를 문자로 변환하기
- 우분투 시간변경
- 자바 파일 한줄씩 읽기
- index 생성
- node js express install
- 디지털오션 드로플릿
- 파이썬
- express install
- node 버전확인
- 파이썬 반복문
- Python
- Node.js express install
- 디지털오션 클라우드서버 생성하기
- 우분투 시간설정
Archives
- Today
- Total
호그래머
Python 문자열 자르기(substring) 23.01.24 본문
728x90
1. Python 문자열 자르기
문자열[시작인덱스:종료인덱스]
한글자 자르기
지정 인덱스 이후로 자르기
범위로 자르기
뒤에서 자르기
test_string="ABC456DEF789GHI0.TXT"
print("01번: "+test_string[0])#A
print("02번: "+test_string[1])#B
print("03번: "+test_string[2])#C
print("04번: "+test_string[5:])#6DEF789GHI0.TXT
print("05번: "+test_string[8:])#F789GHI0.TXT
print("06번: "+test_string[11:])#9GHI0.TXT
print("07번: "+test_string[0:3])#ABC
print("08번: "+test_string[3:6])#456
print("09번: "+test_string[6:9])#DEF
print("10번: "+test_string[-4:])#.TXT
print("11번: "+test_string[0:-4])#ABC456DEF789GHI0
끝
1. 파이썬에서 쉽게 문자열을 자를 수 있습니다.
2. 인덱스 범위를 지정하여 원하는 범위의 문자열을 자를 수 있습니다.
3. 문자열 뒤에서도 원하는 범위로 문자열을 자를 수 있습니다.
728x90
'Python' 카테고리의 다른 글
Python if 사용하기 23.06.26 (0) | 2023.06.27 |
---|---|
Python text 파일 읽기 - 방법1 (파일읽기) 23.06.25 (0) | 2023.06.25 |
Python text 파일 쓰기 - 방법1 (파일쓰기) 23.06.25 (0) | 2023.06.25 |
Python 날짜, 시간표현 (Date, Time) 23.01.24 (0) | 2023.01.24 |
Python 폴더 생성 (make directory) 23.01.24 (1) | 2023.01.24 |
Comments