# 출석번호가 1 2 3 4, 앞에 100을 붙이기로 함 -> 101, 102, 103, 104
students = [1, 2, 3, 4, 5]
print(students)
>> [1, 2, 3, 4, 5]
students = [i+100 for i in students] # students 리스트에 있는 값에 100을 더한 값을 리스트로
바꿔서 students 리스트에 넣음
print(students)
>> [101, 102, 103, 104, 105]
# 학생 이름을 길이로 변환
students = ["Iron man", "Thor", "I am groot"]
students = [len(i) for i in students] # students 리스트에 이름들을 i 에 넣어서 글자의 길이 별로
리스트를 넣음
print(students)
>> [8, 4, 10]
# 학생 이름을 대문자로 변환
students = ["Iron man", "Thor", "I am groot"]
students = [i.upper() for i in students] # students 리스트에 이름들을 전부 대문자로 바꿔서 저장
print(students)
>> ['IRON MAN', 'THOR', I AM GROOT']
'Programming Language > Python' 카테고리의 다른 글
| [기초] 6-2. 전달값과 반환값 (0) | 2021.11.09 |
|---|---|
| [기초] 6-1. 함수 (0) | 2021.11.09 |
| [기초] 5-4. continue 와 break (0) | 2021.11.08 |
| [기초] 5-3. while 문 (0) | 2021.11.08 |
| [기초] 5-2. for 문 (0) | 2021.11.08 |