TIL 21 (2020.08.04)

백은진·2020년 8월 6일
0

TIL (Today I Learned)

목록 보기
21/106
post-thumbnail

<Udemy - Python by Avinash>

1. Pycharm program downloading

  1. Jet Brains 사이트에서 Pycharm 다운로드 함
	 * License ID: 32GJT234HR
  2. pycharm 카테고리 및 파일 만들고, print(“Hello World”) 출력함 ㅎㅎ 
     shift+control+R 키를 누르면 출력값을 바로 볼 수 있다. 

2. Variables and Assignmet (변수와 대입)

1. 우선, 파이썬은 정말 다른 언어에 비해 입력이 쉽다. 
2. 변수를 만들 때, 그냥 age = 21 이런식으로 쓰면, 변수 age에 21이 담긴다. 
3. 변수 예
    1. age = 25
    2. a = “My name is Jean”
    3. jean, jun, nathan = 25, 29, 22
    4. jean, jun, nathan = human
    5. name, age = “jean”, 25

3. Operations and Strings

1. 각 변수에 내용을 담고, 그걸 계산할 수 있다. 
2. age1=12, age2=18 이렇게 숫자를 담고, 
   age1+age2 혹은 age1/age2 혹은 age1%age2 입력
3. firstName=“Jean”, lastName=“Baek” 정보를 담고, 
   firstName+” “+lastName 입력 > Jean Baek 출력 
   (string에는 - % / 기호 사용불가)
4. “Hej”*10
5. sentence=“Jean like to swim”
6. sentence[0] > ‘J’
7. sentence[0:4] > ‘Jean’

4. Placeholders in Strings

1. a
    1. name = Avi
    2. sent = “%s is 15 years old”
    3. sent%name > Avi is 15 years old
    4. sent%(“jake”) > jake is 15 years old
2. b
    1. sent = “%s %s is the President of Republic of Korea”
    2. sent%(“Moon”, “Jaein”) > Moon Jaein is the President of Republic of Korea
3. c
    1. sent = “%s is %d years old”
    2. sent%(“Obama”, 50) > Obama is 50 years old
    3. sent2 = sent%(“Jean”, 21)
    4. sent2 > “Jena is 21 years old”

5. Introduction to Lists

1. a
    1. shopList = [‘Bananas’, ‘Cherries’]
    2. shopList2 = [‘Bread’, ‘Cheese’]
    3. shopList[0] > ‘Bananas’
    4. shopList.append(‘Blueberries’) < 목록추가
    5. shopList[0] = ‘Apples’ < 목록변경
    6. del shopList[1] <목록삭제
    7. len(shopList) >1 < 목록갯수
    8. shopList + shopList2 
2. b
    1. listNum = [1,4,5,7,23,6]
    2. max(listNum) > 23
    3. min(listNum) > 1

6. Introduction to Dictionaries

1. students = {"Bob":12, "Rachel":13, "Emily":15} < words in “” are KEYs, numbers are VALUEs
2. students[“Emily”] > 15
3. students[“Bob”] = 20 > "Bob”:20
4. del students[“Rachel”] > Rachel removed
5. len(students) > 2
6. *If the same keys are more than one, python only recognize the last one.

7. Tuples

1. similar with Lists, but you cannot change, add, or delete items. (*you can delete an whole tup)
2. tup = (‘oranges’, ‘mangostines’, ‘mango’)

8. Conditional Statement

1. if else 구문
    1. 파이썬에서는 줄을 맞추는 것이 중요하다. 예를 들어, if 와 else를 같은 줄에, 각 print를 같은 줄에 맞춰야 작동한다. 
2. 기호
    1. 3 > 2 (greater than)
    2. 3 < 2 (less than)
    3. 3 >= 2 (greater than equal to)
    4. 3 <= 2 (less than equal to)
    5. 3 == 3 (compare to)
    6. (*값을 부여할 때는 equal 1개 사용 / 두 값을 비교할 때는 equal 2개 사용)
    7. 3 != 2 > true (not equal to)(!= 은 “같지 않다”는 뜻)
3. elif
    1. elif (age >= 13 and age < 18): 
    2.      print(“You are a teenager”)
4. and or
    1. if (5>3 and 2>1): > 둘다 참이어야 실행
    2. if (5>3 or 2>1): > 둘 중 하나만 참이면 실행

9. For Loops

1. 출력
    1. list1 = [~~~]
    2. tup1 = (~~~)
    3. for item in list1: 
    4.      print(item) > list1 values 출력
    5. for item in tup1:
    6.      print(item) > tup1 values 출력
2. range
    1. for i in range(1,11):
    2.      print(i) > 1~10 출력 (마지막 숫자 -1 출력됨)
    3.  for i in range(1,11, 2):
    4.      print(i) > 1,3,5,7,9 출력 (1부터 11(10) 사이에서 2씩 더한 숫자 출력됨)
    5. for i in range(0,5):
    6.      for j in range(0,3):
    7.          print(i*j) > 0,0,0,0,1,2,0,2,4,0,3,6,0,4,8 (이유 모르겠음)

10. While Loops

1. 기본
    1. c = 0
    2. while c < 5:
    3.      print(c)
    4.      c = c + 1
    5. > 0,1,2,3,4 출력
2. Break
    1. c = 0
    2. while c < 5:
    3.      print(c)
    4.      if c ==3:
    5.           break
    6.      c = c + 1
    7. > 0,1,2,3 출력
3. continue
    1. c = 0
    2. while c < 5:
    3.      c = c + 1
    4.      if c == 3;
    5.           continue
    6.      print(c)
    7. > 1,2,4,5 출력 (continue이면, 그 숫자는 skip 되나 봄)
4. pass
    1. c = 0
    2. while c < 5:
    3.      c = c + 1
    4.      if c == 3;
    5.           pass
    6.      print(c)
    7. > 1,2,3,4,5 출력 (js의 <div> 처럼 구색맞추기용 코드인가 봄)
profile
💡 Software Engineer - F.E

0개의 댓글