Python Basics: Exploring the Six Common Data Types with Code Examples
This tutorial walks through Python 3's six standard data types—Number, String, List, Tuple, Dictionary, and Set—showing concise code snippets for each type, their typical usage, and the exact console output produced.
Common Python Data Types
Python 3 defines six built‑in types: Number, String, List, Tuple, Dictionary and Set.
Number
int – integer values.
num = 32
print(num) 32float – floating‑point numbers.
# float type
num1 = 3.21
print(num1) 3.21bool – subclass of int with values True and False.
bool1 = True
bool2 = False
print(bool1)
print(bool2)
print(4 < 3) # False
print(11 > 8) # True True
False
False
TrueString
Strings are sequences of characters (letters, digits, underscores, Chinese characters, etc.) delimited by single or double quotes. Triple quotes allow multi‑line literals.
str1 = "hello"
str2 = 'world'
str3 = '''
床前明月光,
疑是地上霜,
举头望明月,
低头思故乡.
'''
print(str1, str2, str3) hello world
床前明月光,
疑是地上霜,
举头望明月,
低头思故乡.List
Lists are mutable sequences defined with []. Elements may be of heterogeneous types and may be nested.
list1 = ['张三', '李四', '王五', '陈六', '徐七']
print(list1)
list2 = [12, 34, 56, 5.32, True, False, "hello"]
print(list2) ['张三', '李四', '王五', '陈六', '徐七']
[12, 34, 56, 5.32, True, False, 'hello']Tuple
Tuples are immutable sequences defined with ().
tup = (12, 43, 9, 87, True, False, "world")
print(tup) (12, 43, 9, 87, True, False, 'world')Dictionary
Dictionaries map immutable keys to values and are defined with {}.
user = {"name": "李四", "age": 35, "sex": "男", "weight": 183}
print(user) {'name': '李四', 'age': 35, 'sex': '男', 'weight': 183}Set
Sets store unordered unique elements and are also defined with {}.
set1 = {121, 67.36, True, False}
print(set1) {False, True, 67.36, 121}Lisa Notes
Lisa's notes: musings on daily life, work, study, personal growth, and casual reflections.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
