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 strings can be represented by a small alphabet "u" in front of the string while assigning.
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 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.
You can search string in a variable by using the below commands.
You can split strings in variables by using the below commands.
You can replace the string in the variable by using the below commands.
The following operators can be used in python: addition (+), subtraction (-), multiplication (*), division (/), modulus(%) operations, etc.
Exponent (x**y) operation
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.