Why You Should know Python | Python Basics
In Cybersecurity (I am speaking from the Pentesting Point of view, as it’s what I currently know), it is a good thing to know a few programming languages. The reason is simple: you’ll most likely have to read some code every now and then, and it would be good if you at least understood a bit. Imagine this: given a web with some code running a simple login page, you download the code to inspect it, and decide to read how the code authenticates the user. Being able to read the code, you may be able to find a way to bypass the simple authentication script. On the other hand, if you don’t know anything about it, you may just see jibberish and move on, or you may not even care to inspect the code and may spend lots of time stuck (I once spent 3 hrs on a TryHackMe room trying to figure it out, only to later find out that I could have edited JavaScript code to complete the challenge).
Of course, knowing every language is either impossible or gonna take way too much time. I recommend knowing a few; the most important is Python. The reason for this is simple: Python is one of the simplest languages to learn, and it is used in many programs. Also, knowing Python syntax helps you learn other languages much more easily, since the syntax is somewhat similar. It’s almost like knowing English and learning another language with the same letters.
Python can be downloaded at https://www.python.org/downloads/, and you can use any editor of your choice. Python also has an interactive IDE that comes with it.
Basic Python stuff
A great place to start is the print function. This function is just used to print whatever’s in the parentheses; it may be a string or variable, or any other data that is in the syntax.
print() #Syntax/usage
# Example 1: Print directly
print("Hello world")
## Result ##
Hello world
##########################################################
#Example 2: Assign a variable
variablename = "Stuff to print"
# Call the print function
print(variablename)
## Result ##
Stuff to printAs demonstrated by the above code, the print function can be called to print whatever is inside the parentheses. A few things to note: If you are printing a string directly, as in Example 1, you NEED to put quotation marks (can be single or double quotation marks), as a string data type is always inside quotation marks. If you are printing a variable that represents a value, you SHOULD NOT put quotation marks on the variable name, as the interpreter will just take the name as a string and not a variable. Also, if you attempt to print a variable that has not been assigned a value, you will get an error. Let me demonstrate:
#Example 3: Not putting quotation marks
print(this string)
## Result ##
SyntaxError: invalid syntax. Perhaps you forgot a comma?
#Example 4: Putting quotation marks on a variable
var_name = "Print this" #assign a variable
print("var_name") #attempt to print "Print this" message.
## Result ##
var_name
#Example 5: Using an unassigned variable
print(var_name) # print the var_name variable
## Result ##
NameError: name 'var_name' is not definedI have been throwing around the “variable” word a lot, but what is it? Maybe you have already understood what it is, but in case you haven’t, a variable is basically a placeholder for a value just like it would be in math. Here the value could be a string, an integer, or whatever. So instead of having to insert a large paragraph in the print function, I could assign a variable and call it whenever I need that paragraph, as I have shown in the above examples.
Get Saze Worldbringer’s stories in your inbox
Join Medium for free to get updates from this writer.
If two different values have the same variable, the last assigned gets acknowledged.
#Example 6: variables
var = "First msg"
var = "Second msg"
#print
print(var)
## Result ##
Second msg
#Example 7: assigning a variable to another variable
var = 6
var = var + 1
#print
print(var)
## Result ##
7In example 7, we originally had the value of var being 6, but in the result we have 7; that’s because we used the original value and added 1, while keeping the same variable name. This reassigned the value to 6 + 1 = 7.
DATA TYPES
Finally, it’s important to be able to distinguish data types early in Python.
Find videos on Penetration testing and Cybersecurity at www.youtube.com/@sazed369







