a=(1+2j)-(3+4j)

a

(-2-2j)



import math

math.pi

3.14...


math.e

2.718...




abs(10)

10


round(1.4)

1

round(1.5)

2


math.factorial(3)

6

math.factorial(100)

100


math.degrees(math.pi)

180.0


math.sin(math radians(90))


try:                      #문제가 없을 경우에 실행할 코드

exept 예외형식1:    #문제가 생겼을때 실행할 코드

exept 예외형식2:    #문제가 생겼을때 실행할 코드

finally:                  #어떠한 일이 있더라도 실행된다.



import datetime

print(datetime.datetime.now())

2016-10-11 10:19:08.543717


import datetime

now = datetime.datetime.now()

print("%s년%s월%s일,%s시%s분%s초"%(now.year,now.month,now.day,now.hour,now.minute,now.second))



from datetime import datetime
now = datetime.now()
print("%s년%s월%s일,%s시%s분%s초"%(now.year,now.month,now.day,now.hour,now.minute,now.second())


#net_1_1

import socket

host_name = socket.gethostname()

IP_address = socket.gethostbyname(host_name)

print("host_name : %s,IP_address : %s"%(host_name,IP_address))



#net_1_2
import socket
remote_host = "www.google.co.kr"
print("IP address of %s : %s"%(remote_host,socket.gethostbyname(remote_host)))

#net_1_4

import socket

# protocol_name = 'tcp','udp'

# port_number = 25, 53, 80

print("port : 25 ---> service name : %s"%socket.getservbyport(25,'tcp'))

print("port : 53 ---> service name : %s"%socket.getservbyport(53,'tcp'))

print("port : 80 ---> service name : %s"%socket.getservbyport(80,'tcp'))


#threading

import threading

count = 0

def on_timer():

    global count

    count += 1

    print(count)

    timer = threading.Timer(1,on_timer)

    timer.start()

    if count == 100:

        print("cancling timer ...")

        timer.cancel()

print("Starting timer...")

on_timer()



상속(Inheritance) : 기존의 클래스가 가지고 있는 필드와 메소드를 그대로 물려받은 새로운 클래스를 만드는 것 

#threading

import threading

from datetime import datetime

def on_timer():

    now = datetime.now()

    print("%s년%s월%s일,%s시%s분%s초"%(now.year,now.month,now.day,now.hour,now.minute,now.second))

    timer = threading.Timer(1,on_timer)

    timer.start()

    key = int(now.minute)

    if key == 0:

        print("cancling timer ...")

        timer.cancel()

print("Starting timer...")

on_timer()




'먼지 낀 책장사이 > Python' 카테고리의 다른 글

테이블 제작, 데이터입력  (0) 2016.11.08
SQLite  (0) 2016.10.18
상속, 오버라이딩, 툴킷  (0) 2016.09.27
Raw파일 읽기, 클래스, 생성자  (0) 2016.09.20
문자열, 구구단, 그림그리기  (0) 2016.09.13