Skip to content

Commit e0f3f46

Browse files
committed
[ADD] Initial blog post of writing formatted strings in Python.
1 parent 5672cb5 commit e0f3f46

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: _posts/2018-08-15-fstrings-in-python.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: post
3+
title: "Fstrings in Python"
4+
date: "2018-08-15 13:55:49 +0530"
5+
tag:
6+
- fstring
7+
- Python
8+
- Python3.6
9+
- FormattedStrings
10+
---
11+
12+
13+
* Fstring: Fstring is one of the coolest feature introduced with this version of
14+
Python. F-String is yet another way of re-presenting formatted strings. At
15+
present, Python already have more than two ways to a format string. This
16+
version introduces yet another way to format the string. In my view, this
17+
option is more concise than all other available options.
18+
19+
Below is the example of fstring.
20+
21+
```python
22+
>>> name = "Jay"
23+
>>> print(f"Hello {name}")
24+
Hello Jay
25+
>>> name = "Vijay"
26+
>>> print(f"Hello {name}")
27+
Hello Vijay
28+
```
29+
30+
Explaination of above exaple:
31+
32+
When you prefix the string with "f", it becomes a formatted string. All values
33+
wrappend inside the curly braces are resolved with the value of variable in
34+
scope.
35+
36+
Exception Raises:
37+
38+
NameError: If the variable isn't defined that it will raise a NameError.

0 commit comments

Comments
 (0)