Standard data that are used in Python variables

01-12-22 Ahmed Obaid 2277 0

The data stored in memory can be of several types. For example, a person's age is stored as a numeric value and their address is stored as alphanumeric characters. Python has different standard data types that are used to define the possible operations on it and the storage method for each.

There are five standard types of data that are used in variables:

Variables with a numerical value (  Numbers )

Variables that store numeric values. Digital objects are created when you assign them a value. for example :


age = 33
price = 10

 The types of data that undefined It is used for numeric variables.

 Python supports four different scalar data types:

 1- Integers ( int )

 Example:


# An integer variable of type int
number = 9

 2- Long integers, which can also be represented in octal and hexadecimal ( long )

 Example:


#An integer variable of type long
long_number = 535633629843L

 3- Ten values ​​( float )

 Example:


# An integer variable of type float
float_number = 3.6

 4- complex numbers

 Example:


# A scalar variable of type complex
complex_number = 9.322e-36j

Numbers and their functions will be explained in detail in a special article later.

Variables with string values ​​( String )

A text string is a string of one or more characters (letters, numbers, and symbols),

 Strings in Python come inside single quotes ( ' ) or double quotes ( " ) for example:


'This is a string in single quotes.'


"This is a string in double quotes."

 You can store a text value inside a particular variable A common example is that you may want to print the first and last name in a sentence and these values ​​are stored in two variables.

 Example:


first_name = 'ahmed'
last_name = "obaid"
print("FirstName :", first_name , "; LastName :", last_name )

 We will get the following result:


FirstName : ahmed ; LastName : obaid

 Text strings and their functions will be explained in a special article later.

 list variables

In Python, a variable can be assigned a value of type list, and list ( list ) is the most versatile of all Python data types. It contains elements separated by commas and enclosed in square brackets ( [ ] ). To some extent, lists are similar to arrays. Lists are used to store multiple elements in a single variable.

Example:


list = ["Ahmed", "Hamza", "Ali"]
print(list)

The output will be:


['ahmed', 'hamza', 'ali']

Lists and their functions will be explained in a special article later.

Tuples variables

In Python, a variable can be assigned a value of type tuples. A tuple is another string data type similar to a list, but its size is fixed, its values ​​are immutable, and it can store values ​​of different types simultaneously. The array consists of a number of values ​​separated by commas. Groups are enclosed within brackets ( ).

Example:


list = ("ahmed", "hamza", "ali")
print(list)

The output will be:


('ahmed', 'hamza', 'ali')

Tuples and their functions will be explained in a special article later.

Variables with a value Dictionary

The variable can be assigned toundefined Python is a value of type list. Python dictionaries are a type of hash table. It consists of (key:value) pairs. The dictionary key can be almost any type of Python, but is usually numbers or text. The value of each element can be accessed through its private key. Dictionaries are enclosed in square brackets ( { } ). for example


dict = { "name": "ahmed", "electric": False, "year": 2022
 }
 print(dict)

 The output will be:


 {name': 'ahmed', 'electric': False, 'year': 2022'}

 Dictionaries and their functions will be explained in a special article later.

 more information

 You may wish to refer to the following resources for additional information on this topic.

 Python documentation

 If you have any questions? Leave it in the comments

 



Tags


Python python variables

Share page