for 키워드를 사용하여 코드를 여러 번 반복 할 수 있다.

마지막 숫자 11은 포함되지 않는다.

결과 값은 1 ~ 10 출력

for i in range(1,11):
    print i


파이썬은 다른 프로그래밍 언어들과 마찬가지로 0부터 계산을 시작 할 수 있다.

결과 값은 0 ~ 9 출력

for i in range(0,10):
    print i


Nested loops

루프는 중첩될 수 있다.

for i in range(0,10):
    for j in range(0,10):
        print i,' ',j


'프로그래밍 > Python' 카테고리의 다른 글

Python Tutorial : Functions [6]  (0) 2016.04.15
Python Tutorial : While loop [5]  (0) 2016.04.15
Python Tutorial : Variables [3]  (0) 2016.04.15
Python Tutorial : If statements [2]  (0) 2016.04.15
Python Tutorial : Text input and output [1]  (0) 2016.04.15

파이썬에서는 변수에 숫자와 텍스트를 넣을 수 있다.

x = 2
price = 2.5
word = 'Hello'


변수에는 공백이나 특수문자를 쓸 수 없다. 변수를 정의하는 3가지 예

word = 'Hello'
word = "Hello"
word = '''Hello'''


변수는 재 정의가 가능하다.

x = 2

# increase x by one
x = x + 1

# replace x
x = 5



파이썬의 조건연산자

>   greater than
<   smaller than
==  equals
!=  is not


조건은 항상 변수와 결합 if 구문

x = int(input("Tell X"))

if x == 4:
    print 'You guessed correctly!'

print 'End of program.'


if else 구문

x = int(input("Tell X"))

if x == 4:
    print 'You guessed correctly!'
else:
    print 'Wrong guess'

print 'End of program.'


'프로그래밍 > Python' 카테고리의 다른 글

Python Tutorial : While loop [5]  (0) 2016.04.15
Python Tutorial : For loops [4]  (0) 2016.04.15
Python Tutorial : Variables [3]  (0) 2016.04.15
Python Tutorial : Text input and output [1]  (0) 2016.04.15
파이썬 기초 - Python이란?  (0) 2016.04.14

+ Recent posts