본문 바로가기

IT/Python

[파이썬] Slicing (자르기)

 

* string 자리 숫자

 

print(student_name[4]) == print(student_name[-1]

 

* Slicing ( 자르기)

예를 들어보자면,

 

abc="abcdefg"

abc[:]returns the entire string

전체를 다 보여준다

abcdefg

 

abc[::2]returns the first char and then steps to every other char in the string

전체에서 첫번째 글자, 그리고 한칸씩 띄워서 글씨를 보여준다

aceg

 

abc[1::3]returns the second char and then steps to every third char in the string

[1: ] 중에서 첫번째 글짜 즉 b, 그리고 3칸뒤인 e가 보여진다.

be

 

* in 은 찾는 기능으로 사용가능하다.

menu = "salad, pasta, sandwich, pizza, drinks, dessert"

print('pizza' in menu)

 

>> True

 

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

[파이썬] range 구문  (0) 2020.06.29
[파이썬] List 관련 (Python)  (0) 2020.06.29
[파이썬] Casting/캐스팅  (0) 2020.06.29
[파이썬] if, elif, else 구문  (1) 2020.06.29
[파이썬] Boolean string methods (Yes or No)  (0) 2020.06.29