python调用类创建类
python调用类创建类
并行迭代
names = ['a1', 'a2', 'a3'] ages = [11, 22, 66] for i in range(len(ages)): print(names[i], 'is', ages[i], 'years old') list_conbine = list(zip(names, ages))
函数zip可用于“缝合”任意数量的序列
names = ['a1', 'a2', 'a3'] ages = [11, 22, 66] list_conbine = list(zip(names, ages)) for name, age in list_conbine: print('method2:', name, 'is', age, 'yeares old')
类的创建:
class Employee: __name = '' #下划线,表示私有private def set_name(self, name1): """ :param name1: """ self.__name = name1 def get_name(self): """ :return: """ return self.__name def greet(self): """ """ print('hello, nice day ...')
类的调用:
class_emp = Employee() class_emp.set_name('tree') get_name = class_emp.get_name() print('员工的名字:', get_name)
if __name__ == '__main__': print_hi('good day') main() product_code = func_switch_case("bag") print(f"bag的产品编号:{product_code}") product_code = func_switch_case2("pencil") print(f"case2_pencil的产品编号:{product_code}") d = {'x': 1, 'y': 2, 'z': 3} for key in d: print(key, 'content:', d[key]) names = ['a1', 'a2', 'a3'] ages = [11, 22, 66] for i in range(len(ages)): print(names[i], 'is', ages[i], 'years old') list_conbine = list(zip(names, ages)) for name, age in list_conbine: print('method2:', name, 'is', age, 'yeares old') class_emp = Employee() class_emp.set_name('tree') get_name = class_emp.get_name() print('员工的名字:', get_name)
欢迎讨论,相互学习。
cdtxw@foxmail.com
分类:
Python
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2022-12-28 qt 调用窗口 mainwindow.cpp:9:78: error: incomplete type 'QDialog' named in nested name specifier qwindowdefs.h:55:7: note: forward declaration of 'QDialog'
2022-12-28 System.InvalidOperationException:“线程间操作无效: 从不是创建控件“Form1”的线程访问它。”
2021-12-28 c# linq查询的等于大于符号是什么意思?