VARRIABLE AND DATA TYPE

Variable:

Any storage space or memory region in a program is referred to as a variable.

In plain English, we may say that a variable is a container that holds some data, and that we use the name of that container to retrieve the data anytime we need it. We’ll make a variable now:

a = 34 # Variable storing an integer

b = 23.2 # Variable storing real number

Here, the variables a and b can be used to obtain 23.2 and 34, respectively. Alternatively, we might change the values in a and b.

Data Types:

The following data types are the most common ones.

  • Integers (of the “int” class”): Used to hold integers.
  • Decimal or floating-point numbers are stored using floating point numbers (class “float””).
  • Strings (of the’str’ class): Used to hold strings.
  • Booleans (of the ‘bool’ class): Used to store values of the True/False type.
  • None: None in Python literally means “Nothing.”

Python’s definition of a variable is as follows:

  • The characters in a variable name can be letters, numbers, and underscores (_).  demo_xyz = “It’s a string variable,” as an example.
  • Only an alphabetic character and an underscore may begin a variable name.
  • It cannot be the first digit. For instance, 5rahul is prohibited and illegal.
  • Within a variable name, no white space may be used.
  • Additionally, it is not advised to utilize restricted words as variable names.
  • Tom, _demo, de_mo, and other examples of acceptable variable names are provided.

Python is a terrific language that does the automatic data type identification for us. It implies that we must enter some data into a variable, and Python knows what kind of data a variable is holding on its own.

# Variable in Python:

abc = “It’s a string variable”

_abcnum = 40 # It is an example of int variable

abc123 = 55.854 # It is an example of float variable

print(_abcnum + abc123) # This will give sum of 40 + 55.854

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in