Posted in

Python Data Types (Part 1): What is a data type in Python?

Python Data Types Part 1
Python Data Types Part 1

Python Data Types

Code:
text = 'Python Programming'

How to Find Data Types in Python?

Code:
text = 'Python Programming'
print(type(text))

Output:
<class 'str'>
Code:
info = 100
values = True
first_list = ['Python', 'Java']
print(type(info))
print(type(values))
print(type(first_list))

Output:
<class 'int'>
<class 'bool'>
<class 'list'>

How Many Kinds of Data Types in Python?

Primitive Data Types

Non-Primitive Data Types

CategoriesData Types
Text Data Typestrings
Sequence Data Typelisttuplerange
Numeric Data Typeintfloatcomplex
Boolean Data Typebool
Set Data Typesetfrozenset
Dictionary Data Typedict
None Data TypeNone
Binary Data Typesbytesbytearraymemoryview

Text Data Type in Python

String data type in Python

Code:
text1 = 'Hello Python'
text2 = '100'
print(type(text1), type(text2))

Output:
<class 'str'> <class 'str'>
Code:
text1 = 'Hello Python'
text2 = "Hello Python"
text3 = '''Hello Python'''
print(text1, text2, text3)
print(type(text1), type(text2), type(text3))

Output:
Hello Python Hello Python Hello Python
<class 'str'> <class 'str'> <class 'str'>

Click to learn more about Python quotes

Sequence Data Type in Python

List data type in Python

Code:
first_list = ['Python', 'Java', 100, True]
print(type(first_list))
print(first_list)

Output:
<class 'list'>
['Python', 'Java', 100, True]
Code:
first_list = ['Python', 'Java', 100, True]
print(first_list[0])
print(first_list[1])
print(first_list[2])
print(first_list[3])

Output:
Python
Java
100
True

Tuple data type in Python

Code:
first_tuple = ('Hello', 100, 'Python', 'Java')
print(type(first_tuple))
print(first_tuple)

Output:
<class 'tuple'>
('Hello', 100, 'Python', 'Java')
Code:
first_tuple = ('Hello', 100, 'Python', 'Java')
print(first_tuple[0])
print(first_tuple[1])
print(first_tuple[2])
print(first_tuple[3])

Output:
Hello
100
Python
Java
Code:
first = 'Hello' 'Python'
second = 'Hello', 'Python'
Code:
first = 'Hello' 'Python'
second = 'Hello', 'Python'
print(type(first))
print(type(second))

Output:
<class 'str'>
<class 'tuple'>
Code:
first = 'Hello'
second = 'Hello',
print(type(first))
print(type(second))

Output:
<class 'str'>
<class 'tuple'>

Range data types in Python

Code:
for values in range(3):
    print(values)

Output:
0
1
2

End of Python Data Types (Part 1)

Click for Python Data Types (Part 2)

4 thoughts on “Python Data Types (Part 1): What is a data type in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *