|
55 | 55 | "metadata": {}, |
56 | 56 | "outputs": [], |
57 | 57 | "source": [ |
58 | | - "import numpy as np\n", |
59 | 58 | "import matplotlib.pyplot as plt\n", |
| 59 | + "import numpy as np\n", |
60 | 60 | "\n", |
61 | 61 | "# You shouldn't use the `seed` function in real science code, but we use it here for example purposes.\n", |
62 | 62 | "# It makes the \"random\" number generator always give the same numbers wherever you run it.\n", |
|
161 | 161 | "outputs": [], |
162 | 162 | "source": [ |
163 | 163 | "print(\n", |
164 | | - " \"\"\"Half light radius\n", |
165 | | - "value: {0}\n", |
166 | | - "unit: {1}\"\"\".format(Reff.value, Reff.unit)\n", |
| 164 | + " f\"\"\"Half light radius\n", |
| 165 | + "value: {Reff.value}\n", |
| 166 | + "unit: {Reff.unit}\"\"\"\n", |
167 | 167 | ")" |
168 | 168 | ] |
169 | 169 | }, |
|
181 | 181 | "outputs": [], |
182 | 182 | "source": [ |
183 | 183 | "print(\n", |
184 | | - " \"\"\"Half light radius\n", |
185 | | - "value: {0.value}\n", |
186 | | - "unit: {0.unit}\"\"\".format(Reff)\n", |
| 184 | + " f\"\"\"Half light radius\n", |
| 185 | + "value: {Reff.value}\n", |
| 186 | + "unit: {Reff.unit}\"\"\"\n", |
187 | 187 | ")" |
188 | 188 | ] |
189 | 189 | }, |
|
200 | 200 | "metadata": {}, |
201 | 201 | "outputs": [], |
202 | 202 | "source": [ |
203 | | - "print(\"{0:.3g}\".format(Reff.to(u.m)))" |
| 203 | + "print(f\"{Reff.to(u.m):.3g}\")" |
204 | 204 | ] |
205 | 205 | }, |
206 | 206 | { |
|
228 | 228 | "outputs": [], |
229 | 229 | "source": [ |
230 | 230 | "print(\n", |
231 | | - " \"\"\"First 10 radial velocity measurements: \n", |
232 | | - "{0}\n", |
233 | | - "{1}\"\"\".format(v[:10], v.to(u.m / u.s)[:10])\n", |
| 231 | + " f\"\"\"First 10 radial velocity measurements: \n", |
| 232 | + "{v[:10]}\n", |
| 233 | + "{v.to(u.m / u.s)[:10]}\"\"\"\n", |
234 | 234 | ")" |
235 | 235 | ] |
236 | 236 | }, |
|
282 | 282 | "outputs": [], |
283 | 283 | "source": [ |
284 | 284 | "sigma = np.sqrt(np.sum((v - np.mean(v)) ** 2) / np.size(v))\n", |
285 | | - "print(\"Velocity dispersion: {0:.2f}\".format(sigma))" |
| 285 | + "print(f\"Velocity dispersion: {sigma:.2f}\")" |
286 | 286 | ] |
287 | 287 | }, |
288 | 288 | { |
|
355 | 355 | "outputs": [], |
356 | 356 | "source": [ |
357 | 357 | "print(\n", |
358 | | - " \"\"\"Galaxy mass\n", |
359 | | - "in solar units: {0:.3g}\n", |
360 | | - "SI units: {1:.3g}\n", |
361 | | - "CGS units: {2:.3g}\"\"\".format(M.to(u.Msun), M.si, M.cgs)\n", |
| 358 | + " f\"\"\"Galaxy mass\n", |
| 359 | + "in solar units: {M.to(u.Msun):.3g}\n", |
| 360 | + "SI units: {M.si:.3g}\n", |
| 361 | + "CGS units: {M.cgs:.3g}\"\"\"\n", |
362 | 362 | ")" |
363 | 363 | ] |
364 | 364 | }, |
|
562 | 562 | "# Average velocity bin width\n", |
563 | 563 | "dv = (v.max() - v.min()) / len(v)\n", |
564 | 564 | "print(\n", |
565 | | - " \"\"\"dra = {0}\n", |
566 | | - "ddec = {1}\n", |
567 | | - "dv = {2}\"\"\".format(dra.to(u.arcsec), ddec.to(u.arcsec), dv)\n", |
| 565 | + " f\"\"\"dra = {dra.to(u.arcsec)}\n", |
| 566 | + "ddec = {ddec.to(u.arcsec)}\n", |
| 567 | + "dv = {dv}\"\"\"\n", |
568 | 568 | ")" |
569 | 569 | ] |
570 | 570 | }, |
|
607 | 607 | " interpolation=\"nearest\",\n", |
608 | 608 | " aspect=\"equal\",\n", |
609 | 609 | ")\n", |
610 | | - "plt.colorbar().set_label(\"Intensity ({})\".format(intcloud.unit))\n", |
| 610 | + "plt.colorbar().set_label(f\"Intensity ({intcloud.unit})\")\n", |
611 | 611 | "plt.xlabel(\"RA (deg)\")\n", |
612 | 612 | "plt.ylabel(\"Dec (deg)\");" |
613 | 613 | ] |
|
746 | 746 | "metadata": {}, |
747 | 747 | "outputs": [], |
748 | 748 | "source": [ |
749 | | - "print(\"{0}\\n{1}\".format(B, B.decompose()))" |
| 749 | + "print(f\"{B}\\n{B.decompose()}\")" |
750 | 750 | ] |
751 | 751 | }, |
752 | 752 | { |
|
0 commit comments