30 Python Concepts I Wish I Knew Way Earlier

<p>Everyone&rsquo;s Python journey is different, and we all learn different concepts at different speeds, in different sequences. But some things ay off a lot more when you learn them early. Here are 30 Python concepts I wish I learn much earlier in my own Python journey.</p> <h1>1) f-strings (formatted strings)</h1> <p>I was taught to convert non-strings into strings before using the&nbsp;<code>+</code>&nbsp;operator to concatenate it with a string. But this got annoying very quickly.</p> <pre> # ANNOYING name = &#39;tom&#39; age = 5 s = &#39;my name is &#39; + name + &#39; and my age is &#39; + str(age) # using f-strings name = &#39;tom&#39; age = 5 s = f&#39;my name is {name} and my age is {age}&#39;</pre> <p>We need to spend less effort caring about spaces and data types when we use f-strings. Additionally, f-strings enable use to do some cool things:</p> <pre> name = &#39;tom&#39; age = 5 height = 1.44 s = f&#39;{name=} {age=} {height=}&#39; # name=&#39;tom&#39; age=5 height=1.44 pi = 3.14159265 s = f&#39;pi is {pi:.2f}&#39; # pi is 3.14 </pre> <p>And many many other cool functionalities.</p> <h1>2) Tuple Unpacking (with &amp; without *)</h1> <pre> person = [&#39;tom&#39;, 5, &#39;male&#39;] name, age, gender = person # name=&#39;tom&#39;, age=5, gender=&#39;male&#39;</pre> <p>We can use tuple unpacking to assign multiple variables in one line.</p> <pre> letters = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;] first, second, *others = letters # first=&#39;A&#39;, second=&#39;B&#39; # letters = [&#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;]</pre> <p>We can add a&nbsp;<code>*</code>&nbsp;character in front of variables to signify that it should contain everything else that hasn&rsquo;t been unpacked.</p> <p><a href="https://levelup.gitconnected.com/30-python-concepts-i-wish-i-knew-way-earlier-3add72af6433">Click Here :-</a></p>