File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments