zoukankan      html  css  js  c++  java
  • Python学习笔记字符串操作之小结之表格打印

     随笔记录方便自己和同路人查阅。

    #------------------------------------------------我是可耻的分割线-------------------------------------------

      编写一个名为 printTable()的函数,它接受字符串的列表的列表,将它显示在组织良好的表格中,

    每列右对齐。假定所有内层列表都包含同样数目的字符串。

    #------------------------------------------------我是可耻的分割线-------------------------------------------

      示例代码:

    #! python 3
    # -*- coding:utf-8 -*-
    # Autor: Li Rong Yang
    tableData = [['apples', 'oranges', 'cherries', 'banana'],
    ['Alice', 'Bob', 'Carol', 'David'],
    ['dogs', 'cats', 'moose', 'goose']]
    
    def printTable(list_name):#定义函数接收字符串列表的列表
        for i in range(len(list_name)):#循环列表长度
            list_name[i] = ' '.join(list_name[i])#把列表的列表转换为字符串
        #print(list_name)
        for i in range(len(list_name)):#循环转换后列表的的长度
            print(list_name[i].rjust(35))#把列表内容右对齐打印
    printTable(tableData)
    

      运行结果:

  • 相关阅读:
    mysql 主从复制原理
    java操作ldap
    ldap数据库--ldapsearch,ldapmodify
    ldap数据库--ODSEE--ACI
    ldap数据库--ODSEE--schema
    ldap数据库--ODSEE--复制协议
    ldap数据库--ODSEE--suffix
    ldap数据库--ODSEE--卸载
    ldap数据库--ODSEE--安装
    WebService--cxf
  • 原文地址:https://www.cnblogs.com/lirongyang/p/9573368.html
Copyright © 2011-2022 走看看