1. 将字符串转换为元组 `python my_string = "hello" my_tuple = tuple(my_string) print(my_tuple) 2. 元组的解构赋值 `python my_tuple = (1, 2, 3) a, b, c = my_tuple print(a, b, c) 3. 元组作为函数的返回值 `python def get_coordinates(): x = 10 y = 20 return x, y coo...
1.2 使用 tuple()函数 创建元组 我们除了可以使用()创建元组,还可以使用tuple()函数创建元组,但 tuple() 偏向于将某个类型转换为元组,具体用法见下述: cre_tuple = tuple(('a', 'b', 'c')) # 注意双括号 print(cre_tuple) print(type(cre_tuple)) 1. 2. 3. ('a', 'b', 'c') <class 'tup...
namespace py = boost::python; boost::python::object calc_func = modules[job->module].attr("Calc"); py::object result_tuple = calc_func(s); /* result */ r0 = py::extract(result_tuple[0]); /* center */ r1 = py::extract(result_tuple[1][0]); r2 = py::extract(result_tuple...
1. 将字符串转换为元组 `python my_string = "hello" my_tuple = tuple(my_string) print(my_tuple) 2. 元组的解构赋值 `python my_tuple = (1, 2, 3) a, b, c = my_tuple print(a, b, c) 3. 元组作为函数的返回值 `python def get_coordinates(): x = 10 y = 20 return x, y coo...