• 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 👈

Basic Data Types in Python

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

Instructions to receive Claude Fable 5 for free for 30 days
Tips

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity
Tips

Delete all Event Logs on Windows to remove traces of activity

June 15, 2026
Instructions for creating Minecraft-style food photos
Tips

Instructions for creating Minecraft-style food photos

June 9, 2026
Get free Cambridge courses to prepare for IELTS, Starters, Movers
Tips

Get free Cambridge courses to prepare for IELTS, Starters, Movers

June 4, 2026
How to record reaction videos with Android phones, no app needed
Tips

How to record reaction videos with Android phones, no app needed

June 1, 2026
Instructions on how to get Google AI Pro 1 year for free for new accounts
Tips

Instructions on how to get Google AI Pro 1 year for free for new accounts

June 1, 2026
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 to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity

Delete all Event Logs on Windows to remove traces of activity

June 15, 2026
Instructions on how to get the latest 200GB MultCloud for free in 2026

Instructions on how to get the latest 200GB MultCloud for free in 2026

June 14, 2026
Instructions to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity

Delete all Event Logs on Windows to remove traces of activity

June 15, 2026
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 to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

6789 kv999

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

6789 kv999

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