def say_hello(name, age):
return f"Hello {name} I'm {age} years old" -> string formatting
string formatting : ""앞에 f를 붙이고 해당하는 변수를 {}로 감싸면 해당 변수가 출력됨
"Hello ", name, … 의 방식으로도 가능(번거롭다.)
hello = say_hello(age = "23", name = "lalala") -> keyword argument
함수를 호출 할 때 각 argument의 이름을 써넣으면 순서에 상관 없이 해당 argument로 값이 들어간다.
list선언 : s_list = [1, 2, 3]
tuple선언 : s_tuple = (1, 2, 3) -> cannot fix
dict선언 : s_dict = {1, 2, 3}
list는 c언어의 배열과 비슷함. [1, "hi", True]식의 list도 가능
tuple은 list지만 한 번 지정해놓으면 수정할 수 없음.
dict는 요소에 index가 없음.
for문으로 요소를 불러오면 무작위로 나옴
dict에 대한 부가적인 설명
https://docs.python.org/3/library/stdtypes.html#typesmapping
Built-in Types — Python 3.9.1 documentation
The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some collection classes are mutable. The methods that add, subtract,
docs.python.org
# 1만 출력한다.
for x in s_list: # s_tuple을 해도 같은 값
if(x == 2):
break
print(x)
# 무작위로 출력된다.
for x in s_dict:
if(x == 2):
break
print(x)
is와 == 의 차이점
https://medium.com/peloton-engineering/the-dangers-of-using-is-in-python-f42941124027
The dangers of using ‘is’ in Python
This blog post covers a strange integer bug that I encountered, and it corresponds to a talk I gave at PyCon Canada. In this post you’ll…
medium.com
==, !=는 값(value)를 비교하는 것.
is, is not는 가리키는 object가 같은 지 검사
Module import하기
import math(기본 파이썬 module)
from math import ceil as c -> math를 불러오면 math안의 모든 것을 불러오기 때문에 비효율적이라서 사용하고자 하는 함수만 불러온다
다른 파이썬 파일에서도 불러올 수 있음
ex) from my_py import plus
댓글 영역