3 quick tips to help you code a little more efficiently
This is a tutorial on how to code a little more efficiently in Python.
Have you ever forgotten to put quotations/parentheses around a string? Well here is a tip to save you a few seconds. Double click/highlight the text that you want to put quotations around, then just press the ' or " or ( key and the highlighted text will have quotations/parentheses around it!
Have you ever made a bunch of functions with attributes, but when you needed to add another attribute, it took forever to change all of the functions? Well, there are two solutions to this problem.
It is possible to have Multiple Cursors in Repl. Click where you want to edit the text, then use Control + Click and click where you want to add the second cursor. Then, when you type something, all cursors will respond, typing the same thing in multiple places
The second solution is that you can use
Ctrl + H to open up a find & replace bar. On the top, paste in the code you want to replace, and on the bottom input the code that you want to replace it with. You can now replace everything easily.
This is a quicker way to write your import statements: instead of writing
import random import time import os import sys
You can use:
import random, time, os, sys
which can save you from typing a few lines of code.
Have you ever had to indent a lot of code? You can indent a large block of code by highlighting all of it, then pressing
Tab(to indent) or
Shift + Tab(to unindent).
I hope this little tutorial helps you code a little bit more efficiently. Please consider upvoting!
#1 is a valid tip
#2: Regex search-and-replace is much faster:
If you have
foo = 1 #foobar bar = 2 #dfa floo = 3
and you want to change them to _foo_2, _bar_2, and _floo_2, you can use:
(.*) = (.*)
_$1_2 = $2
#3 is hard to read. You don't do