왕초보를 위한 Python 문법 익히기

기본 컨텐츠 및 사용자가 직접 참여하여 만들어진 다양한 내용을 검색합니다.

들여쓰기,4개의 공백을 들여쓰기의 단위로 사용하라.,hanging indent,좋은 예,# 구분자를 사용하여 정렬하기 foo = long_function_name(var_one, var_two, var_three, var_... Read more

피해야할 이름,숫자 1과도 비슷하고, 영문 대문자 I 하고도 비슷하여 피해야 합니다.,숫자 0과 비슷하여 피해야 합니다.,숫자 1과 비슷하고, 영문소문자 l(엘)과도 비슷하여 피해야 합니다.,패키지명, 모듈명,모듈 이름은 짧아야 하고, 전부 소문자여야 합니다. 가독성... Read more

뭔가?,꾸며주다,대상 함수를 wrapping하고, 이 wrapping된 함수의 앞뒤에 추가적으로 꾸며질 구문들을 정의해서 손쉽게 재사용 가능하게 해주는 것,왜 쓰나?,# 만약, 이런코드가 기존에 존재했다고 칩시다. import datetime def main_fun... Read more

*args,파라미터를 몇개를 받을지 모르는 경우 사용한다. args는 튜플 형태로 전달된다.,>>> def print_param(*args): >>> print args >>> for p in args: >>> print p >>> print_param('... Read more

>>> print 방가~ File "<stdin>", line 1 print 방가~ ^ SyntaxError: invalid syntax,File "<stdin>", line 1,>>> def f(a, b): ... return (a ... Read more

__init__() #메서드(초기화),# bookstore.py class Book: def setData(self, title, price, author): self.title = title self.price = price ... Read more

class Person: # 눈 두 개, 코 하나, 입 하나... eyes = 2 nose = 1 mouth = 1 ears = 2 arms = 2 legs = 2 # 먹고 자고 이야기하고... def... Read more

>>> f = open('C:\\Python27\\readme.txt') >>> f.readline() 'This is Python version 2.7.1\n' >>> f.readline() '============================\n',>>> f = ... Read more

matplotlib은 플롯(그래프)을 그릴 때 많이 쓰이는 파이썬 라이브러리입니다. matplotlib 프로젝트의 홈페이지 주소는 다음과 같습니다.,from pylab import * x = linspace(-1.6, 1.6, 10000) f = lambda x: ... Read more

>>> import random >>> random.random() 0.90389642027948769,>>> random.randrange(1,7) 6 >>> random.randrange(1,7) 2,>>> range(1,7) [1, 2, 3, 4, 5, 6],>... Read more