Dev/Python 12

[Coursera] Programming for Everybody (Python) - 10. Tuples

10. Tuples Tuples은 세번째 Collection! List와 Dictionary에 이어서. List랑 비슷함. 순서가 변하지 않고, 0번부터 시작. But, Tuples are "immutable" list와 다르게 tuple 은 한 번 생성하면 수정할 수 없어. string 같아 >>> x = [9, 8, 7] >>> x[2] = 6 >>> print (x) [9, 8, 6] >>> y = 'ABC' >>> y[2] = 'D' Traceback: blah blah... >>> z = (5, 4, 3) >>> x[2] = 0 Traceback: blah blah... Thing not to do with tuples sort() append() reverse() => Traceback을 보게..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 9. Dictionaries

9. Dicionaries What is a Collection? Collection은 일종의 짐보따리 같은거지. 안에 아무 거나 넣을 수 있는. 우리는 아무거나 넣어서 그걸 아무데나 들고 다닐 수 있어. 일종의 편리한 짐가방처럼. What is not a "Collection" 우리가 아는 대부분의 variables은 하나의 값만을 가짐. 만약 우리가 새로운 값을 넣는다면? 오래된 값은 over written됨. list와 dictionary의 차이점은 내부에 값이 어떻게 구성되어 있는가이다. A story of Two Collections.. List A linear collection of values that stay in order. 값이 index별로 차곡차곡 들어간다. 0, 1, 2, 3....

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 8. Lists

8. Lists A List is a kind of Collection A collection allows us to put many values in a single variable 우리가 많은 values 들을 하나의 편리한 가방 안에 넣을 수 있기 때문에 좋아! What is not a "Collection" 대부분의 variables은 하나의 값을 가지지. 만약 우리가 새로운 값을 variable 안에 넣으면 오래된 값은 지워져. 그리고 새로운 값을 덮어쓰게 됨 List Constants List constants는 [] (square brakets) 으로 쌓여있음. 그리고 내부에 있는 elements들은 , (comma) 로 구분됨. list 의 elements는 Python object 의 무..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 7. Files

7. Files 그동안 우리가 한 건 그냥 정말 python이랑 논 거. 그냥 CPU랑 Main Memory사이를 왔다갔다 하면서. 절대 여길 떠나지 않았지! 그래서 우리는 이번엔 이제 Secondary Memory를 사용해보려고 해! permanent media! 우리는 python을 이용해서 파일을 쓰거나 읽을 수 있어. File Processing 텍스트 파일은 sequence of lines라고 볼 수 있지 Opening a File 일단 Python에게 우리가 어떤 파일을 읽을건지 말해줘야 한다. open() function을 사용해서! open() 은 file handle 을 return해! 뭐 그냥 file 관련 동작을 수행할 수 있는 variable? 어떻게 보면 "[File > Open]..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 6. Strings

6. Strings String Data Type A string is a sequence of characters. A string literal uses quotes 'Hello' or "Hello" For strings, + means concatenate When a string contains numbers, it is still a string We can convert numbers in a string into a number using int() Reading and Converting raw_input() => 모든 입력을 string으로 받음 Looking Inside Strings index와 square brackets을 이용해 string내부의 single character를 얻..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 5. Loop

5. Loop Repeated Steps while이 if와 다른 점은 condition을 만족하는 한 indent된 구문을 계속해서 다시 실행한다는 것 iteration variables : some variable that is changing each time through the loop. iteration variable controls how many times the loop runs An Infinite Loop 우리는 사실 대부분의 경우 이 무한루프를 원하지 않지. 대부분은 실수야. 무한루프는 절대 끝나지 않는다구! Another Loop never run. 단 한 번도 조건을 만족시키지 못한거지. == Zero Loop Breaking Out of a Loop The break stat..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 4. Functions

4. Functions Stored (and reused) Steps Functions은 저장해놨다가 다시 쓰고 쓰고 그게 기본적인 idea 계속해서 사용하게 되는 logic을 저장해두었다가 쉽게 반복해서 불러다 쓰는거지. def keyword python은 def구문을 보면 오! 이건 function이군! 하면서 코드를 기록하기 시작해. indent 블록이 다시 앞으로 나올 때까지 (def 구문이 끝날 때까지) def 함수명(): 함수는 이렇게 정의한다. 이렇게 정의하고 나면, 함수명() 으로 언제든 불러다 쓸 수 있지! Python Function python에는 두 종류의 function이 있음 Built-in functions (Guido wrote this code!!!! HAHA) Python..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 3. 조건문, 예외처리

3.1 Conditional Statements conditional steps의 statement는 실행될 수도 있고, 실행되지 않을 수도 있다. if question : statement If the question(condition) is false then python will skip all the statement Comparison Operator : Greater than != : Not equal Comparison operator look at variables but do not change the variables Indentation Python에서 Indentation은 매우 중요함 Indentation은..

Dev/Python 2015.08.31

[Coursera] Programming for Everybody (Python) - 2. Expressions, Types

2.1 Expressions Constants And Variable Constants : 숫자, 문자, 문자열 등 고정된 값. 바뀌지 않는다. 문자열은 ‘ 와 “ 둘 다 쓸 수 있음 Variables : 컴퓨터의 메모리에 저장할 수 있는 값. 우리는 이름으로 값을 가져다 쓸 수 있음. 그리고 물론, Constants와 다르게 값을 바꿀 수 있다. Naming Rules 문자나 _ 로 시작 문자, 숫자, _ 허용 Case sensitive Reserved Words - Sentences or Lines x = 2 Assignment Statement : assign a value to a variable x = x + 2 Assignment with expression : right side is an ..

Dev/Python 2015.08.31