[Python Basics] Python basic data types (necessary for newbies)

        Python is a weakly typed language, so the data type of variables can change dynamically. Python’s basic data types include the following:

  1. Integer type (int): represents an integer, such as 1, 2, 3, etc.
  2. Float: represents a number with a decimal part, such as 1.0, 2.5, 3.14, etc.
  3. Boolean (bool): represents true or false, there are only two values, True and False.
  4. String (str): Represents a string of characters. You can use single quotes or double quotes to create strings, such as 'hello', "world", etc.
  5. List: represents a set of ordered values, which can contain any type of data, such as [1, 2, 'hello', True], etc.
  6. Tuple: represents a set of ordered values, similar to a list, but cannot be modified, such as (1, 2, 'hello', True), etc.
  7. Set: Represents a group of unordered unique values ​​that can perform set operations, such as {1, 2, 3, 4}, etc.
  8. Dictionary (dict): represents a set of key-value pairs, used to store related data, such as {'name': 'Tom', 'age': 18}, etc.

        These basic data types can be combined to form more complex data structures. For example, lists can contain tuples, and tuples can contain lists. Python also supports other advanced data types, such as sets and dictionary comprehensions, making it easier to create sets and dictionaries.

Supongo que te gusta

Origin blog.csdn.net/Steel_nails/article/details/134087091
Recomendado
Clasificación