예제 1. for문을 사용해서 출석번호를 바꾸기
(조건)
1. 출석번호 students는 1, 2, 3, 4로 index 되어 있습니다.
2. 출석번호 앞에 새롭게 100을 붙이기로 합니다.
3. for문을 사용합니다.
(코딩)
students = [1,2,3,4]
print(students)
students = [i+100 for i in students]
print(students)
(출력)
[1, 2, 3, 4]
[101, 102, 103, 104]
예제 2. 학생 이름을 길이로 바꾸기
students = ["Kim kyung ho", "Parl Sungjong", "Lee chol"]
students = [len(i) for i in students]
print(students)
예제 3. 학생 이름을 대문자로 바꾸기
students = ["Kim kyung ho", "Parl Sungjong", "Lee chol"]
students = [i.upper() for i in students]
print(students)
'SW.AI 트랙 > python' 카테고리의 다른 글
[Python] 파이썬. range 함수 (0) | 2023.03.17 |
---|---|
[Python] 파이썬 예제풀이. for, 택시 승객수 구하기 (0) | 2023.03.13 |
[Python] 파이썬 예제풀이. while, 카페에서 손님 호출하기 (0) | 2023.03.13 |
[Python] 파이썬 예제풀이. lower, upper, isupper, len, find, count문자열처리함수 (0) | 2023.03.13 |
[Python] 파이썬 예제풀이. sentance, 문자열을 출력하는 3가지 방법 (0) | 2023.03.13 |