반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- spring
- 비주얼스튜디오코드
- 파일명일괄변경
- 파이썬기초
- python
- CSS
- 코딩
- 파이썬터틀
- 오블완
- springquickstart
- Java
- 캐나다일상
- THINKINGRUN
- 스프링
- 티스토리챌린지
- 스프링퀵스타트
- 스타벅스주문
- springquick
- 캐나다
- 이클립스
- html
- Eclipse
- 달리기
- 파이썬
- vscode
- 프로그래밍
- 생각하는달리기
- 파이참
- 영어스타벅스
- 자바
Archives
- Today
- Total
LIKE A DIAMOND
python 004. 리스트 다루기a 본문
728x90
반응형
python 004. 리스트 다루기a
루프를 사용하면 리스트의 모든 항목에 같은 일을 할 수 있다.
루프를 통해 효율적인 작업을 할수 있다.
#같은 항목에 같은일을 할때 for 루프를 사용
friends = ['mike', 'alice', 'smith']
for friend in friends:
print(friend)
mike
alice
smith
에러가 난다면 들여쓰기에 문제가 있기 떄문. 아래는 그냥 들여쓰기 없이 그냥 썼을경우
>>> friends = ['mike', 'alice', 'smith']
>>> for friend in friends:
... print(friend)
File "<stdin>", line 2
print(friend)
^
IndentationError: expected an indented block
코딩줄 설명(회색)
1.배열
2.for를 사용하여 friends의 첫째 값을 읽어 friend에 저장.
3.프린트 다음 다시 for구문으로가서 두번째 값을 출력. 그리고 다음 smith출력. 다음 없으므로 프로그램 마무리.
*주의 for구문 이용시 명명에 있어 s와 단수 구분을 잘해서 지어보자
#루프를 좀더 활용하기1
friends = ['mike', 'alice', 'smith']
for friend in friends:
print(friend.title() + " have a good mind.")
Mike have a good mind.
Alice have a good mind.
Smith have a good mind.
#루프를 좀더 활용하기2
friends = ['mike', 'alice', 'smith']
for friend in friends:
print(friend.title() + " have a good mind.")
print(friend.title() +"'s cat is cute."+"\n")
print("Thank you.")
...
Mike have a good mind.
Mike's cat is cute.
Alice have a good mind.
Alice's cat is cute.
Smith have a good mind.
Smith's cat is cute.
Thank you.
#루프를 좀더 활용하기3 (커맨드상에선 오류뜸./ 지니상에선 그대로 출력)
friends = ['mike', 'alice', 'smith']
for friend in friends:
print(friend.title() + " have a good mind.")
print("I like "+ friend.title())
Mike have a good mind.
Alice have a good mind.
Smith have a good mind.
I like Smith
불필요한 들여쓰기에 주의하며 코딩을하자
#콜론(":"을 잊은경우 <<< 에러발생! 위치 찾기도 어렵다.
@
728x90
반응형
'notUsed_STUDY' 카테고리의 다른 글
[Python] 001.Hello World! #codeAcademy (0) | 2018.08.06 |
---|---|
python 004. 리스트 다루기b (0) | 2017.07.22 |
python 003. 리스트 소개 (0) | 2017.07.15 |
python 002. 변수와 단순한 데이터 타입 (0) | 2017.07.15 |
python 001. 파이썬 설치 확인 및 설치 및 hello world (0) | 2017.07.09 |
Comments