들여쓰기,4개의 공백을 들여쓰기의 단위로 사용하라.,hanging indent,좋은 예,# 구분자를 사용하여 정렬하기 foo = long_function_name(var_one, var_two, var_three, var_... Read more
들여쓰기,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
1. 크기 확인: len(),2. 자료형 확인: type(),3. 숫자로 변환: int(),4. 문자형으로 변환: str(),5. 반올림: round(),6. 절대값: abs(),7. 최대값,최소값: max(), min(),8. 정렬: sorted(),9. 합: su... 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 Fridge: def __init__(self): self.isOpened = False self.foods = [] def open(self): self.isOpened = True ... Read more
class Person: # 눈 두 개, 코 하나, 입 하나... eyes = 2 nose = 1 mouth = 1 ears = 2 arms = 2 legs = 2 # 먹고 자고 이야기하고... def... Read more
class Amazon: strength = 20 dexterity = 25 vitality = 20 energy = 15 def attack(self): return 'Jab!!!',>>> import diablo... Read more
>>> class Singer: # 가수를 정의하겠느니라… ... def sing(self): # 노래하기 메서드 ... return "Lalala~" ... >>> t... Read more
pickle,>>> users = {'kim':'3kid9', 'sun80':'393948', 'ljm':'py90390'} >>> f = open('users.txt', 'w') >>> import pickle >>> pickle.dump(users, f) >>> ... 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