Day13 - Python02-파이썬 사용해보기

January 25, 2017

Day13 - Python02-파이썬 사용해보기

파이썬 프로젝트 폴더에서 아래 명령어 실행

projects/python 폴더를 추천

(fc-python) ➜  Python git:(master) ✗ ipython
Python 3.4.3 (default, Oct  7 2016, 07:18:15) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 

Python버전이 3.4.3으로 정확히 출력되는지 확인


아래 명령어 실행

In [1]: 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!

파이썬의 철학(Zen of Python)을 표현한 시

아래 명령어 실행

24 * 7


각종 용어

리터럴 (Literal)
변하지 않는 고정된 데이터 자체의 표현

표현식(expression)
값을 의미하는 표현 또는 값을 반환하는 표현

>>> sec = 60
>>> 365*24*sec	# 표현식
525600				# 정수 525600의 리터럴 값

구문(statement)
값의 의미를 지니지 않으며, 어떠한 목적을 수행하는 코드

>>> for char in '안녕하세요':		# 구문 (제어문)
...   print(char)
... 





실습

  1. 파이썬 인터프리터를 계산기처럼 사용해서 1년이 총 몇 초인지 계산해보시오.
In [2]: year = 365
   ...: day = 24
   ...: hour = 60
   ...: second = 60
   ...: 

In [3]: year * day * hour * second
Out[3]: 31536000