Python2 PHP's explode() 함수를 Python으로 처리할 경우 string을 분할 하는 함수를 사용하면 된다. import string string.split(the_string, the_separator) 예를 들어 보면 아래와 같다. >>>print "this is a test string!".split(' ') ['this', 'is', 'a', 'test', 'string!'] >>>print "this is a test string!".split(' ', 2) ['this', 'is', 'a test string!'] 2013. 1. 7. Python 이차원배열 생성 방법 가로, 세로 크기 만큼의 2차원 배열을 만들 경우 아래와 같이 테스트를 할 수 있다. #create width x height matrix matrix = [[0 for col in range(width)] for row in range(height)] for row in range(height): for col in range(width): matrix[row][col] = 0 if col == 0 and row == 0: matrix[row][col] = 1 if col == width-1 and row == height-1: matrix[row][col] = 20 for row in matrix: print row 만약 가로 크기 3, 세로 5의 크기를 가지고 있을 경우 아래와 같은 결과가 출력된다.. 2012. 10. 18. 이전 1 다음