Hey Everyone, I am Vikram Salunke and welcome to Python for InfoSec.
This is part 3 and in post we will see Variables.
In Python a variable refers to data stored in memory or we can call them text labels that point to an area in memory containing objects like integers, strings or any other data types. Python reserves a memory space for the variables when program declares them.
This is my Kali machine running on VirtualBox. Let's go to Python and we are in a interactive way of Python. Let's declare variable num1

num1 = 22

Let's print num1

print num1


So what happens here? When Python interpreter executes this command, it creates a text label as a num1 and points to memory location containing integer object of value 22.
So anytime your program referes to variable num1, it knows that you are referring to memory address that current contain the value 22.

Now just suppose this is a memory. When we declare num1 = 22
22 got stored into memory and num1 is pointing to that memory address where the 22 is stored.

Now, let's define another variable such as name and give a value "Vikram". So "Vikram" will get save into the memory and variable name will point to that memory address where "Vikram" is stored.


Now, let's execute

name = "vikram"

print name

In Python we do not have to explicitly declare the type of a variable. Python interpreter decides, the type and how much memory to reserve.
Now let's try boolean type

male = True

print male

ok, so num1 is integer type, name is a string and male is a boolean type. So, Python interpreter decided data type and memory allocation for variable.


Programmers use variables to store data and process it.

Rules and Guidelines

Now there are some Rules and Guidelines for variables.

[*] Such as Python is case-sensitive that means Str is different from str.
[*] Python variables can contain only letter, numbers and underscores.
[*] Variable can start with letter or underscore but not with number
for eg. num1 is allowed
but 1num is not allowed.
because it is staring with number.
[*] And in variable spaces are not allowed.

If you want to join our in person class then please click here we are doing trainings in some upcoming InfoSec conferences.
And if you have any doubts, any questions then you can tweet me @vikramsalunke20
We are uploading daily new videos on YouTube click here to subscribe.
If you want to solve the exercises on this topic those are below. Solve the exercises and check your understandings. Thank you :)