示例:
num = 10
str_num = str(num)
print(str_num) # 输出: "10"
示例:
str_num = "10"
num = int(str_num)
print(num) # 输出: 10
示例:
str_num = "10.5"
num = float(str_num)
print(num) # 输出: 10.5
示例:
str_nums = "12345"
nums = list(str_nums)
print(nums) # 输出: ['1', '2', '3', '4', '5']
示例:
key_value_pairs = [("a", 1), ("b", 2), ("c", 3)]
my_dict = dict(key_value_pairs)
print(my_dict) # 输出: {'a': 1, 'b': 2, 'c': 3}
示例:
my_list = [1, 2, 3, 3, 4, 5]
my_set = set(my_list)
print(my_set) # 输出: {1, 2, 3, 4, 5}
示例:
my_list = [1, 2, 3]
my_tuple = tuple(my_list)
print(my_tuple) # 输出: (1, 2, 3)
示例:
num = 0
is_zero = bool(num)
print(is_zero) # 输出: False
示例:
num = 10
print(type(num)) # 输出: <class 'int'>
示例:
my_list = [1, 2, 3, 4, 5]
print(len(my_list)) # 输出: 5
这些是Python常见的工厂函数用法示例,可以根据需要选择适合的函数进行对象转换或其他操作。