[ (코드) #(출력문) ] 또는
[
(코드)
"""
(출력문)
"""
] 형식으로 입력
------
"""
참고 : Escape 코드
\n : 개행
\t : 탭
\\ : \ 문자
\' : ' 문자
\" : " 문자
\r : 캐리지 리턴
\f : 폼 피드
\a : 벨 소리
\b : 백 스페이스
\000 : 널 문자
'''
"""
print("'you'") # 'you'
print('\'you\'') # 'you'
print('"you"') # "you"
print("""'you'""") # 'you'
print('\\you\\\n\n\n') # \you\ + (enter 3번)
print('\t\t\ttest') # (tab 3번) + test
# 기본 출력
print('Hello Python!') # Hello Python!
print("Hello Python!") # Hello Python!
print("""Hello Python!""") # Hello Python!
print('''Hello Python!''') # Hello Python!
print('''''Hello Python!''''') # ''Hello Python!
print()
# Seperator 옵션 사용
# 코드 앞에 인덴트 되면 작동 x
print('T', 'E', 'S', 'T', sep='') # TEST
print('2019', '02', '19', sep='-') # 2019-02-19
print('niceman', 'googld.com', sep='@') # niceman@googld.com
# end 옵션 사용
print('Welcome To ', end='')
print('the black parade', end=' ')
print('piano notes') # Welcome To the black parade piano notes
print() # enter
# format 사용 [], {}, ()
print('{} and {}'.format('You', 'Me')) # You and Me
print("{0} and {1} and {0}".format('You', 'Me')) # You and Me and You
print("{a} are {b}".format(a='You', b='Me')) # You are Me
# %d, %f, %s (실수, 정수, 문자)
print("%s's favorite number is %d" % ('Python', 7)) # Python's favorite number is 7
print("Test1: %5d, Price: %4.2f" % (776, 6534.123)) # Test1: 776, Price: 6534.12
print("Test1: {0: 5d}, Price:{1: 4.2f}".format(776, 6534.123)) # Test1: 776, Price: 6534.12
print("Test1: {a: 5d}, Price: {b:4.2f}".format(a=776, b=6534.123)) # Test1: 776, Price: 6534.12
# Python 철학
import this
"""
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"""
# Python 3.x 기본 인코딩
import sys
# - 입력 인코딩
print(sys.stdin.encoding) # utf-8
# - 출력 인코딩
print(sys.stdout.encoding) # utf-8
# 출력문
print('My name is Goodboy!') # My name is Goodboy!
# 변수 선언
myName = 'Goodboy'
# 조건문
if myName == "Goodboy":
print('Ok') # Ok
# 반복문
for i in range(1, 10):
for j in range(1, 10):
print('%d * %d = ' % (i,j), i*j)
"""
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
4 * 1 = 4
4 * 2 = 8
4 * 3 = 12
4 * 4 = 16
4 * 5 = 20
4 * 6 = 24
4 * 7 = 28
4 * 8 = 32
4 * 9 = 36
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
9 * 1 = 9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
"""
# 변수 선언(한글)
이름 = "좋은사람"
# 출력
print(이름) # 좋은사람
# 함수 선언(한글)
def 인사():
print("안녕하세요. 반갑습니다.")
인사() # 안녕하세요. 반갑습니다.
# 함수 선언
def greeting():
print('Hello!')
greeting() # Hello!
# 클래스
class Cookie:
pass
# 객체 생성
cookie = Cookie()
# 정보 값 출력
print(id(cookie))) # 1759481154056
print(dir(cookie)))
"""
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
"""
print(cookie.__class__)) # <class '__main__.Cookie'>
print(cookie.__hash__)) # <method-wrapper '__hash__' of Cookie object at 0x00000199A93FCA08>
------
+ 참고 링크