File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,23 @@ Variable data type is automatically determined by Python. They only need to be a
878725
8888```
8989
90+ * ` _ ` can be used between digits for readability
91+ * introduced in Python v3.6
92+
93+ ``` bash
94+ >>> 1_000_000
95+ 1000000
96+ >>> 1_00.3_352
97+ 100.3352
98+ >>> 0xff_ab1
99+ 1047217
100+
101+ # f-strings formatting explained in a later chapter
102+ >>> num = 34 ** 32
103+ >>> print(f' {num:_}' )
104+ 10_170_102_859_315_411_774_579_628_461_341_138_023_025_901_305_856
105+ ```
106+
90107** Further Reading**
91108
92109* [ Python docs - numbers] ( https://docs.python.org/3/tutorial/introduction.html#numbers )
@@ -162,6 +179,11 @@ Hello World
162179>> > word = ' buffalo '
163180>> > print (word * 8 )
164181buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo
182+
183+ # Python v3.6 allows variable interpolation with f-strings
184+ >> > msg = f ' { str1} there '
185+ >> > msg
186+ ' Hello there'
165187```
166188
167189* Triple quoted strings
201223** Further Reading**
202224
203225* [ Python docs - strings] ( https://docs.python.org/3/tutorial/introduction.html#strings )
226+ * [ Python docs - f-strings] ( https://docs.python.org/3/reference/lexical_analysis.html#f-strings ) - for more examples and caveats
204227* [ Python docs - List of Escape Sequences and more info on strings] ( https://docs.python.org/3/reference/lexical_analysis.html#strings )
205228* [ Python docs - Binary Sequence Types] ( https://docs.python.org/3/library/stdtypes.html#binary-sequence-types-bytes-bytearray-memoryview )
206229* [ formatting triple quoted strings] ( https://stackoverflow.com/questions/3877623/in-python-can-you-have-variables-within-triple-quotes-if-so-how )
You can’t perform that action at this time.
0 commit comments