Aug 12, 2019

Variables | Python programming

You know that variable is a memory space ant it contains a value. When we talk in low level that's a binary number. When we examine the variable or when we use it. Let's get it clearly. A variable is a temporary storage that can hold a string , integer or a float value etc. You know that string is an array of characters while integer can hold number. A float can contain a floating point number. Hear I wrote a simple python script to demonstrate the usage of variables.
[email protected]:~/programming$ cat tmp1.py
#!/usr/bin/env python 
x = 3 
print (x) 
print (x +3)
x = 5
print (x) 
x = 3 * 4 
print (x)
[email protected]:~/programming$ python tmp1.py
3
6
5
12
[email protected]:~/programming$
First I declared a variable names x and assigned a value 3 to it. Note that we have used equal sign for this but it doesn't mean x is equal to 3. We just use x as a container for value 3. Now there is another point to note about. If you divide two integers the answer also be an integer. Even it has a floating point numbers they will be dropped and only integer value will be returned.
[email protected]:~/programming$ cat tmp1.py
#!/usr/bin/env python
x = 12
y = 5
print (x/y)

[email protected]:~/programming$ python tmp1.py
2
So if we want correct answer we want to use floats instead integers. We can use float() function to convert integers to floating point numbers. [email protected]:~/programming$ cat tmp1.py #!/usr/bin/env python x = float(12) y =float(5) print (x/y) [email protected]:~/programming$ python tmp1.py 2.4
[email protected]:~/programming$ cat tmp1.py
#!/usr/bin/env python 
x = float(12)
y =float(5)
print (x/y)

[email protected]:~/programming$ python tmp1.py
2.4
[email protected]:~/programming$
I have allocated complete tutorial for discuss about strings. So I don't go to discus them hear. Thanks for reading. :-)
Jun 17
Simple crackme tutorial for beginners - 01

Today I selected a basic crackme to demonstrate crackme solving with GDB. Also, we can solve this....

Jun 06
Best programming languages for hackers

Do you want to learn hacking? That's great, it is an awesome topic to learn. Some of you may....

Aug 20
CIA law of cryptography

Today I selected an important topic in cryptography. We can call or as the base of cryptography.....

Replying to 's comment Cancel reply
CATEGORIES
ABOUT AUTHER
Thilan Danushka Dissanayaka

Thilan Dissanayaka

Hi, I'm Thilan from Srilanka. An undergraduate Engineering student of University of Ruhuna. I love to explorer things about CS, Hacking, Reverse engineering etc.

SOCIAL
RANDOM ARTICLES