What are the basic data types in python
What are the basic data types of python? Let me introduce them to you one by one:
1. Numbers ---> int class
Of course, for numbers, Python’s number types are Int integer type, long long integer type, float floating point number, complex complex number, and Boolean value (0 and 1). Here we only introduce the integer type.
In Python2, the size of integers is limited, that is, when the number exceeds a certain range, it is no longer of int type, but of long type. In Python3, regardless of the size of the integer The length is collectively called an integer.
The main methods are as follows:
int -->Convert the string data type to int type, Note: The content in the string must be numbers
bit_length() -->Convert the number to binary and return the minimum number of binary digits
2, Boolean value --->bool class
For Boolean values, there are only two results, True and False, which correspond to 0 and 1 in binary respectively. There are too many values of True, we only need to know what the values of False are---》None, empty (i.e. [ ]/( ) /" "/{ }), 0;
Related recommendations: "python video tutorial"
3. String --->str class
About string is Python The most commonly used data type in , it has many uses. We can use single quotes '' or double quotes "" to create strings.
Strings cannot be modified. All about characters, we can introduce strings from aspects such as indexing, slicing, length, traversal, deletion, splitting, clearing whitespace, case conversion, determining what starts with, etc.
Create string
Slice
Index--> index(), find()
The difference between index() and find() The point is: if the character or sequence of the index is not in the string, for index--》ValueError: substring not found, and for find--> returns -1.
Length-->len()
Note: The len() method--> can also be used for other data types, such as checking the number of elements in lists, tuples, and dictionaries .
Delete--> del
Judge string content--> isalnum(), isalpha(), isdigit()
Case conversion--> capitalize(), lower(), upper(), title(), casefold()
Determine what starts and ends--> startswith(), endswith()
Extension-- >expandtabs()
Formatted output-->format(), format_map()
Join method
Split--> split(), partition( )
Replacement-->replace
Replacement-->makestran 、translate
4、List --->list class
A list is composed of a series of elements arranged in a specific order. Its elements can be any data type, such as numbers, strings, lists, tuples, dictionaries, Boolean values, etc., and its elements can also be Modified.
The form is:
names = ['little-five","James","Alex"]2 #or 3 names = list(['little-five" ,"James","Alex"])
Index, slice
Append-->append()
Expand-->extend()
Note: The difference between extend and append: --> The former adds elements as a whole, while the latter decomposes elements of data types and adds them to the list. Example:
insert() -->insert
pop() -->remove
remove()-->remove, del --> ;Delete
sorted()-->Sort, the default is forward order, add reverse =True, it means reverse order
5, Tuple --->tuple class
A tuple is an unmodifiable list. Its characteristics are similar to those of list. It is identified using parentheses instead of square brackets.
#Tuple name = ("little-five","xiaowu")print(name[0])
6. Dictionary --->dict class
The dictionary is a series of key-value pairs, each key-value pair is separated by commas, each key corresponds to a value, and the corresponding value can be accessed by using the key. disorderly.
The definition of the key must be immutable, that is, it can be a number, a string, a tuple, a Boolean value, etc.
The definition of value can be any data type.
Traverse -->items, keys, values
7, collection -->set class
About the definition of set: In my opinion, a set is like a basket. You can store things in it and take things out of it. However, these things are unordered and it is difficult for you to specify which one to take separately. things; at the same time, it can be filtered through certain methods to get the part of the things you need. Therefore, sets can be created, added, deleted, and relationally operated.
Characteristics of collections:
1. Deduplication
2. Unordered
3. Each element must be unique The variable type is (hashable type, which can be used as the key of the dictionary).
Create: set, frozenset
Add: add, update
Delete: pop, remove, discard
Relational operations: intersection &, union | , difference set - , intersection complement set^ , issubset , isupperset
Determine whether the relationship between two sets is a subset or parent set--> issubset , isupperset
The above is the detailed content of What are the basic data types in python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.
