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)
复制代码

 

posted @   txwtech  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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查询的等于大于符号是什么意思?
点击右上角即可分享
微信分享提示