강의

멘토링

커뮤니티

Inflearn Community Q&A

dreaming18177639's profile image
dreaming18177639

asked

Python from Basics to Advanced Taught by Silicon Valley Engineers

Using Abstract Base Class (ABC)

from typing import List, Protocol

Resolved

Written on

·

346

·

Edited

1

from typing import List, Protocol

여기서 List 자료형은 원래 내장되있는거 아닌가요? 왜 from typing을 하는거죠?

from typing 한 List와 원래 알고있던 list 자료형은 다른건가요?

def calculate_total(items: List[Item]) -> float:

여기서 List의 들어있는 데이터하나가 무슨 자료형인지 나타내려면 List[]로 쓰나요?

string이면 List['str']? List[str]로 쓰나요?

python알고리즘

Answer 1

0

altoformula님의 프로필 이미지
altoformula
Instructor

안녕하세요 남기정님,

  • 여기서 List 자료형은 원래 내장되있는거 아닌가요? 왜 from typing을 하는거죠? from typing 한 List와 원래 알고있던 list 자료형은 다른건가요?

    • 사용할 때는 혼용해서 사용하는데 보다 자세하게 표시하려면 typing을 쓰시면 됩니다.

  • 여기서 List의 들어있는 데이터하나가 무슨 자료형인지 나타내려면 List[]로 쓰나요? string이면 List['str']? List[str]로 쓰나요?

    • List[str]로 씁니다. 밑에 예제 보시면 될 듯 합니다.

from typing import List

def process_strings(strings: List[str]) -> None:
    for string in strings:
        # Do something with each string
        print(string)

# Example usage:
my_strings = ["hello", "world", "Python"]
process_strings(my_strings)
dreaming18177639's profile image
dreaming18177639

asked

Ask a question