Table of Contents
Built-in data types in Python
Python Numeric Data Type
Python string data type
Python sequence data type
Python data binary type
Python mapping data types
Python Boolean Data type
Python Set data type
in conclusion
Home Backend Development Python Tutorial What are the different built-in types in Python?

What are the different built-in types in Python?

Aug 19, 2023 pm 02:53 PM
list tuple dict (dictionary)

What are the different built-in types in Python?

In this article, you will learn about Python data types and their use in writing Python programs. You'll learn their purpose, syntax, and how to apply them in your program through examples. The Python language needs no introduction. It's very powerful, adaptable, fast and easy to learn.

One of the languages ​​that continues to expand and gain more and more popularity every year is Python. Python is an object-oriented, interpreted computer language used for general-purpose programming. This tutorial will teach us about various data types in Python programming language.

Built-in data types in Python

There are different types of data types in Python. Some built-in Python data types include -

  • Numeric data types - int, float, complex

  • String data type - str

  • Sequence type - list, tuple, range

  • Binary types - bytes, bytearray, memoryview

  • Mapped data type - dict

  • Boolean type - bool

  • Set data type - set, frozenset

Python Numeric Data Type

In Python, the numeric data type is used to save numerical values.

Integers, floating point numbers, and complex numbers belong to Python’s number categories. They are defined in Python as int, float and complex classes.

  • int − Stores a signed integer of unlimited length.

  • float − Save a floating point number, accurate to 15 digits after the decimal point.

  • complex − Stores complex numbers.

Python string data type

A string is a collection of Unicode symbols. In Python, the name of a string is str. Use single or double quotes to represent strings. It is acceptable to use three quotes """ or "' to represent multiple strings. Between quotes, each character is part of the string.

The only limitation is the memory resources of the machine system, any number of characters can be used. In Python programming, deleting or updating a string will result in an error. Therefore, the Python programming language does not allow changing strings.

Python sequence data type

  • List − List is the only flexible data type available in Python. It is similar to an array in C/C in some ways. However, what’s noteworthy about lists in Python is that they can store many types of data at the same time. A list is an ordered collection of information represented by commas and square brackets ([]). (,)

  • Tuple − Lists and tuples are comparable in many ways. Tuples hold collections of elements of various data types, just like lists. The components of a tuple are separated by commas (,) and brackets (). Tuples are read-only data structures since the size and value of elements cannot be changed.

  • Range − The range() method in Python returns a list of integers contained within the specified range. It is most commonly used to iterate over a series of integers using Python loops.

Python data binary type

  • bytes − A bytes object is generated through the bytes() function. It can generate an empty bytes object of the required size, or convert the item to a bytes object. bytes() and bytearray() return different types of objects: bytes() returns an immutable object, while bytearray() returns a mutable object.

  • bytearray − The bytearray() function returns a byte array object of specified bytes. Provides a modifiable sequence of numbers from 0 to x to 256.

  • memoryview − Python programs can use memoryview objects to access the internal data of objects that implement the buffer protocol without copying. You can use the memoryview() method to directly read and write an object's byte-oriented data without copying.

Python mapping data types

  • dict − In Python, a dictionary is a collection of data items stored in an unordered manner, similar to a map. Dictionaries consist of key-value pairs, as opposed to other data types that can only contain a single value. To improve the efficiency of the dictionary, key-value pairs are included in the dictionary. A comma "separates each key", whereas each key-value pair of a dictionary data type is separated by a colon.

Python Boolean Data type

  • bool − True and False are the two predefined values ​​provided by the Boolean type. Use these values ​​to determine the truth or falsity of the provided statement. It is identified by bool class. Any non-zero integer or the letter "T" can be used to represent true, while the number "0" or the letter "F" can represent false.

Python Set data type

  • set − An unordered collection of data types is called a Python Set. It has unique, iterable, and mutable (can be changed after creation) components. The order of items in a collection is undefined; it may produce a modified sequence of elements. Use the built-in method set() to build a set, or give a comma-separated list of elements enclosed in curly braces. It can contain multiple types of values.

  • frozenset − The frozenset() method returns an immutable frozenset object whose initial elements come from the provided iterable. Frozen collections are immutable versions of Python collection objects. The elements of a collection can be changed at any time, but once a frozen collection is created, its elements cannot be changed.

in conclusion

In this section, we studied Python’s data types. In more detail, we looked at two of the data types, None and Numeric. As we have seen, numeric data comes in four different forms: integers, floating point numbers, Boolean values, and complex numbers. We have an overall understanding of the various Boolean operators and comparison operators for the Boolean type. Unlike statically typed languages ​​like C or Java, Python does not require an explicit declaration of the data type of a variable. In dynamically typed languages ​​like Python, the interpreter infers the data type of a variable based on the type of the value passed to it.

The above is the detailed content of What are the different built-in types in Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

What are regular expressions? What are regular expressions? Mar 20, 2025 pm 06:25 PM

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

See all articles