Code Monkey home page Code Monkey logo

python-practice's Introduction

Practicing Python from basic to advanced

  • 학습 목표: 군데군데 비어있는 파이썬 지식 채우기
  • 기간: 2023-10-14 ~ 12-31
  • 자료: 파이썬 코딩 도장 (남재윤 저)
    • 책 후기: 강력추천! 책 곳곳에 궁금증을 해소해주는 지식들이 알차게 들어있다.

python-practice's People

Contributors

wondrive avatar

Watchers

 avatar

python-practice's Issues

[unit 35] static method v.s. class method

1. 둘이 헷갈렸던 이유:

둘의 공통점은

  • 클래스 변수에 접근할 수 있다
  • 인스턴스 변수에 접근할 수 없다
    따라서 둘을 비슷하게 사용할 수도 있지만, 쓰임의 차이가 있다.

2. 둘의 쓰임의 차이

  • static method: 기능적인 로직을 제공함. pure function, 즉 외부 변수를 바꾼다거나 하는 영향을 미치지 않음. 이는 클래스 변수에 접근할 수 있음에도 굳이 클래스 변수를 변경하는 용도로 사용되지 않는다는 말이다.
  • class method: 클래스 변수에 접근할 때 사용함.

3. 궁금증

수행할 수 있는 기능은 똑같은데, 왜 굳이 용도를 나눠놨을까?

[unit 40] 파이썬에서 for문과 else의 특별한 관계

unit40. 제너레이터 연습문제 풀다가 챗지피티의 도움을 받는 와중에 이상한 걸 발견해 뒷목 잡을뻔했다.
다음은 소수(prime number)를 찾는 예제 풀이과정인데 for과 같은 들여쓰기로 else를 사용할 수 있다는 것이다..


image

[unit 8] print (a is -6)

# 1
a = -5
print( a is -5 )   # True

# 2
a = -6
print( a is -6 )  # False

'#2'의 결과가 False인 이유는,
파이썬은 -5~256의 작은 정수들을 미리 캐싱하여 메모리에 상주시킴.

따라서
-5는 어느 변수에 저장해도 호출시 같은 메모리 주소를 참조하지만,
-6은 변수 생성시 각각 다른 메모리에 -6을 저장하고, 호출시 다른 메모리 주소를 참조함.

[unit 24] raw 문자열 (r'경로')

문자열 앞에 r을 붙이면 raw 문자열이 되어 이스케이프 시퀀스를 그대로 표현함.
따라서 \\가 아닌 \만 써도 됨.

print(r'C:\Users\monkey\AppData\Local\Programs\Python\Python38-32\python.exe')

출력 결과: C:\Users\monkey\AppData\Local\Programs\Python\Python38-32\python.exe

오늘도 가려운 곳 긁기 완료.

[unit 11] len(한글)

arr = '안녕하세요'
print( len(arr) )            # python 2 version: 5 * 3 = 15 byte
print( len(arr) )            # python 3 version: 5 length

파이썬 버전에 따라 한글, 한자, 일본어의 길이는 달라지므로 주의

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.