ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

实验二

2022-04-13 11:00:19  阅读:158  来源: 互联网

标签:end name list better 实验 print than




 

x = list(range(10))
print('整数输出1: ', end = '')
for i in x:
print(i, end=' ')
print('\n整数输出2: ', end = '')
for i in x:
print(f'{i:02d}', end = '-') # 指定每个整数输出宽度占两列,不足两列,左边补0
print('\n整数输出3: ', end = '')
for i in x[:-1]:
print(f'{i:02d}', end = '-')
print(f'{x[-1]:02d}')
print('\n字符输出1: ', end = '')
y1 = [str(i) for i in range(10)] # 函数str()用于把其它类型对象转换成字符串对象
print('-'.join(y1))
print('字符输出2: ', end = '')
y2 = [str(i).zfill(2) for i in range(10)] # 方法.zfill()用于对字符串进行格式化,
指定宽度为2列,不足左边补0
print('-'.join(y2))

# 把姓名转换成大写,遍历输出
name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan',
'cocteau twins']
# 实现方式1
for name in name_list:
print(name.title())
print()
# 实现方式2
name_list_captilize = [name.title() for name in name_list]
print('\n'.join(name_list_captilize))

name_list = ['david bowie',
             'louis armstrong',
             'leonard cohen',
             'bob dylan',
             'cocteau twins']
num=[1,2,3,4,5]
name_list1 = [name.title() for name in name_list]

i=1
for i in range(5):
       print(num[i],'.',name_list1[i],end='')
       print()

 

import this

text = '''The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!'''

line = text.count('\n')+1
print(f'行数:{line}')

x=text.split(' ')
word = len(x)
print(f'单词数:{word}')

count = len(text)
print(f'字符数:{count}')
space = text.count(' ')
print(f'空格数:{space}')

 

 

标签:end,name,list,better,实验,print,than
来源: https://www.cnblogs.com/miaoqiuyousi/p/16139146.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有