Skip to content

Commit 9170a4c

Browse files
committed
up
1 parent b9b4ece commit 9170a4c

2 files changed

Lines changed: 175 additions & 112 deletions

File tree

expressions-datatypes.ipynb

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,69 @@
18431843
"str([1, 2, 3]) + ' + ' + str([4, 5, 6])"
18441844
]
18451845
},
1846+
{
1847+
"cell_type": "markdown",
1848+
"metadata": {},
1849+
"source": [
1850+
"**f-문자열**\n",
1851+
"\n",
1852+
"`str()` 함수를 이용하여 문자열을 연결하는 것보다 **f-문자열**(f-string)을 사용하면 훨씬 편리하다. 문자열을 나타내는 따옴표 앞에 `f`를 붙이고, 문자열 안에 중괄호 `{}`를 사용하여 표현식을 넣으면 평가된 결과가 바로 문자열에 삽입된다. 문자열에 대한 보다 자세한 내용은 나중에 다룬다."
1853+
]
1854+
},
1855+
{
1856+
"cell_type": "code",
1857+
"execution_count": 1,
1858+
"metadata": {},
1859+
"outputs": [
1860+
{
1861+
"name": "stdout",
1862+
"output_type": "stream",
1863+
"text": [
1864+
"6 apples\n",
1865+
"7.6은 부동소수점\n",
1866+
"[1, 2, 3]는 리스트\n"
1867+
]
1868+
}
1869+
],
1870+
"source": [
1871+
"print(f'{6} apples')\n",
1872+
"print(f'{7.6}은 부동소수점')\n",
1873+
"print(f'{[1, 2, 3]}는 리스트')"
1874+
]
1875+
},
1876+
{
1877+
"cell_type": "markdown",
1878+
"metadata": {},
1879+
"source": [
1880+
"f-문자열의 중괄호 안에는 임의의 표현식이 사용될 수 있다.\n",
1881+
"예를 들어, 아래 예제는\n",
1882+
"\n",
1883+
"1. 변수(`age`, `height`)를 직접 사용할 수 있다는 점과 \n",
1884+
"2. 그 안에서 `age + 1` 등의 연산 표현식까지 바로 계산된다는 점\n",
1885+
"\n",
1886+
"을 보여준다."
1887+
]
1888+
},
1889+
{
1890+
"cell_type": "code",
1891+
"execution_count": 3,
1892+
"metadata": {},
1893+
"outputs": [
1894+
{
1895+
"name": "stdout",
1896+
"output_type": "stream",
1897+
"text": [
1898+
"나이는 20살, 키는 175.5cm 입니다. 내년에는 21살이 됩니다.\n"
1899+
]
1900+
}
1901+
],
1902+
"source": [
1903+
"age = 20\n",
1904+
"height = 175.5\n",
1905+
"\n",
1906+
"print(f'나이는 {age}살, 키는 {height}cm 입니다. 내년에는 {age + 1}살이 됩니다.')"
1907+
]
1908+
},
18461909
{
18471910
"cell_type": "markdown",
18481911
"id": "80428f43-b590-4bcf-9f65-9b6fee3178d9",
@@ -2456,7 +2519,7 @@
24562519
"name": "python",
24572520
"nbconvert_exporter": "python",
24582521
"pygments_lexer": "ipython3",
2459-
"version": "3.12.12"
2522+
"version": "3.13.12"
24602523
},
24612524
"toc": {
24622525
"base_numbering": 1,

0 commit comments

Comments
 (0)