Short Tutorial: Variable and Data Types in Python

Python is a high-level programming language created by Guido Van Rossum in 1989. Python is very popular among programmers and testers as it is very easy to learn and use to automate any repetitive IT task very easily. In this article, we will cover variables, different types of operators, and python lists.

Variables in Python

In python, no need to mention the type of variables unlike C, Java etc.  Here, the variable is just a reference to an object instead of a data type. In the below example, the same variable is used for string and numerals.

The complex number can be assigned by using variable a and can be checked by using the built-in isinstance() function as mentioned in the below example.

To find the memory location of the variable, use either "id" function or "__repr__".

Different string variables examples as given below:

Unicode String

Unicode strings can be represented by a small alphabet "u" in front of the string while assigning.

String Operations

Python strings are immutable objects in python. You can't change it once it is created.

Now, you can't change the string by assigning  var1[3]  to some other character as mentioned below.

Strings are immutable. In the below example, variable var2 is assigned with the string 'AllAboutTesting', and variable an assigned with the string 'InformationSecurity'. Now, again variable var2 assign with the value of variable a. Variable a reassign with the string 'AllAboutTesting'. Now print variables a and var2. Variable var2 still contains the value of variable a which signifies strings are immutable.

Concatenation of strings

The repeated sequence in the string to use as a buffer overflow. You can create those files by using the * operator.

Convert an integer into a string and vice-versa by using the int and str functions.

String Methods

You can search string in a variable by using the below commands.

<variable_name>.find('<search_string>')

You can split strings in variables by using the below commands.

<variable_name>.split('<search_string>')

You can replace the string in the variable by using the below commands.

<variable_name>.replace('<replace_string>', '<new_string>')

String Formatting

Numbers

The following operators can be used in python: addition (+), subtraction (-), multiplication (*), division (/), modulus(%) operations, etc.

Exponent (x**y) operation

Comparison Operators

greater than (>), less than (<), greater than equal to (>=), less than equal to (<=), equal to (==), and not equal to (!=).

Lists in Python

It is defined as a collection of homogenous or heterogeneous objects. It is a collection of similar or different data types elements which is ordered and changeable.

The list can be altered and searched by different functions. Below are the examples showing built-in append(), replace(), pop(), and reverse() functions.

Subscribe us to receive more such articles updates in your email.

If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!

Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

10 Blockchain Security Vulnerabilities OWASP API Top 10 - 2023 7 Facts You Should Know About WormGPT OWASP Top 10 for Large Language Models (LLMs) Applications Top 10 Blockchain Security Issues