• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

Basic Data Types in Python

AnonyViet by AnonyViet
January 30, 2023
in Tips
0

The data type is one of the most important components of python. You can do a lot of interesting things with these data types. It is a fact that in python, all data types are objects.

Join the channel Telegram of the AnonyViet 👉 Link 👈

python data type

The data type is like a specification about the type of data you want to store in memory, and python has several built-in data types:

  • String text type: str
  • Numeric types: int, float, complex
  • Sequence types: list, tuple, range
  • Mapping type: dict
  • Set data type: set, frozenset
  • Boolean type: bool
  • Binary type: byte, bytearray, memoryview

Now let’s categorize all these data types using the function type() to display the data type of the variable.

Text format

String data type str

str stands for string (string) used to store text in python. Strings can be written in double or single quotes, so you can write like this:

Eg:

String data type str python

Result:

Hello, world!
<class 'str'>

Number type

Integer data type int

int stands for integer (integer) used to store integers (positive integers and negative integers).

Eg:

Integer data type python

Result:

4
<class 'int'>

float . real number data type

float stands for real number (decimal).

Eg:

python float real number data type

Result:

3.14
<class 'float'>

A complex number has a real and imaginary part, each of which is a real number. Complex numbers can be written in two forms: real + (imag)jcomplex(real, imag).

Eg:

Basic Data Types in Python 14

Result:

(5+10j)
<class 'complex'>

Sequence type data type

list

List (list) is a data type where you can store a set of data. List can also contain different data types. Lists can also sort, change elements, and allow duplicates

Eg:

Basic Data Types in Python 15

Result:

['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
<class 'list'>

tuple

Tuple is a data type where you can store a collection of data. Tuples can also contain different data types. Tuples are sortable, cannot change elements, and allow elements to be duplicated.

Eg:

Basic Data Types in Python 16

Result:

('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
<class 'tuple'>

range

The range type represents an immutable (unchangeable) sequence of numbers. Usually used to repeat a specific number of times in a for loop.

Eg:

Basic Data Types in Python 17

Result:

range(0, 10)
<class 'range'>

Mapped data type

dict

dict stands for dictionary in python. Dict is used to store data values ​​in key:values. Dict is an unordered, mutable set, and no duplicates are allowed.

Eg:

Basic Data Types in Python 18Result:

{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
<class 'dict'>

Data type Set

set

set is a data type where you can hold a set of data. Set can also contain different data types. Set is unordered and unindexed and does not allow duplicate elements.

Eg:

Basic Data Types in Python 19

Result:

{'Black Widow', 'Iron Man', 'Thor', 'Hawkeye', 'Hulk', 'Captain America'}
<class 'set'>

frozenset

The frozenset data type can be created by the function frozenset(). Jaw frozenset() accepts an iterable object and returns an immutable frozenset object (just like a set object, just immutable).

Eg:

Basic Data Types in Python 20

Result:

frozenset({'cherry', 'banana', 'apple'})
<class 'frozenset'>

Boolean type

bool

bool stands for boolean in python. Booleans represent one of two values: True or False.

Eg:

Basic Data Types in Python 21

Result:

True
<class 'bool'>
False
<class 'bool'>

Binary type

bytes

The byte data type can be created in two ways: using the byte() function or using the “b” prefix.

Eg:

Basic Data Types in Python 22

Result:

b'hello'
<class 'bytes'>
b'Hello'
<class 'bytes'>

bytearray

Jaw bytearray() returns a bytearray object. It can convert objects to bytearray objects.

Eg:

Basic Data Types in Python 23

Result:

bytearray(b'\x00\x00\x00\x00')
<class 'bytearray'>

memoryview

jaw memoryview() returns an object in the memory view of a specified object.

Eg:

Basic Data Types in Python 24

Result:

<memory at 0x2b4f7a8a7408>
<class 'memoryview'>

Note

As you have seen, some data types can also be implemented using their constructors. This same technique can also be applied to any data type.

Eg:

Basic Data Types in Python 25

Result:

Hello, World!
4
3.14
(5+10j)
['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
range(0, 10)
{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
{'apple', 'cherry', 'banana'}
frozenset({'banana', 'cherry', 'apple'})
True
False
b'\x00\x00\x00\x00'
bytearray(b'\x00\x00\x00\x00')
<memory at 0x2b8346a29408>

If you guys support and I find this article view is high, I will do some more articles comparing data types in python. So please support me.

The article achieved: 5/5 – (100 votes)

Tags: BasicdataPythontypes
Previous Post

Free Keylogger Tool to Hack Password

Next Post

Download R-Studio 8.13 RAID Server Level Data Recovery Software

AnonyViet

AnonyViet

Related Posts

4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
How to create Google Ai Pro 12 months free with Indian student account
Tips

How to create Google Ai Pro 12 months free with Indian student account

July 27, 2025
Next Post
Download R-Studio 8.13 RAID Server Level Data Recovery Software

Download R-Studio 8.13 RAID Server Level Data Recovery Software

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply