python3----ljust rjust center
Python中打印字符串时可以调用ljust(左对齐),rjust(右对齐),center(中间对齐)来输出整齐美观的字符串,使用起来非常简单,包括使用第二个参数填充(默认为空格)。看下面的例子就会明白了:
print('|', '*'.ljust(10), '|')
print('|', '*'.ljust(10, '-'), '|')
print('|', '*'.rjust(10, '-'), '|')
print('|', '*'.center(10, '-'), '|')
for a in range(1, 6):
print('a = '.ljust(5), repr(a).ljust(10), 'b = '.ljust(5), repr(a * 2))
attention: '|'与'*'为逗号,'*'与ljust()间为点号
repr函数和反引号用来获取对象的可打印的表示形式
输出结果:
| * |
| *--------- |
| ---------* |
| ----*----- |
a = 1 b = 2
a = 2 b = 4
a = 3 b = 6
a = 4 b = 8
a = 5 b = 10
python3----ljust rjust center的更多相关文章
- Python: ljust()|rjust()|center()字符串对齐
通过某种对齐方式来格式化字符串 ①对于基本的操作,可以使用字符串的ljust(),rjust(),center() ②函数format()同样可以用来很容易的对齐字符串,使用<,>,~
- python ljust,rjust,center,zfill对齐使用方法
字符串在输出时的对齐:S.ljust(width,[fillchar]) #输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格. S.rjust(width,[fillcha ...
- python center, ljust, rjust
例子 >>> s = "jihite" >>> s.center(, "*") '**jihite**' >>& ...
- Python3 与 NetCore 基础语法对比(String专栏)
汇总系列:https://www.cnblogs.com/dunitian/p/4822808.html#ai Jupyter排版:https://www.cnblogs.com/dunitian/p ...
- Python3 与 C# 基础语法对比(String专栏)
Code:https://github.com/lotapp/BaseCode 多图旧排版:https://www.cnblogs.com/dunitian/p/9119986.html 在线编程 ...
- Python基础(中)
前言 print(" _ooOoo_ ") print(" o8888888o ") print(" 88 . 88 ") print(&q ...
- format()的简单实用 笔记
# 关于format和format_map的使用# 如果要使用输出的字符串对其不仅仅是可以使用format,还可以使用ljust/rjust/center来处理,输出当然也可以是使用%来进行操作,但是 ...
- python字符串及字符串操作
字符串介绍 1.字符串在内存中的存储: 2.字符串相加: 3.字符串的格式化: In [1]: a = 100 In [2]: a Out[2]: 100 #100<255,在堆内存下占用了一个 ...
- Python拾遗(2)
包括Python中的常用数据类型. int 在64位平台上,int类型是64位整数: 从堆上按需申请名为PyIntBlcok的缓存区域存储整数对象 使用固定数组缓存[-5, 257]之间的小数字,只需 ...
随机推荐
- fedora25安装和docker-ce_清华源
docker-ce_清华源 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/fedora/ fedora25 docker-ce版本: htt ...
- Idea 代码编辑错误不飘红提示
Power Save Mode 勾选去掉即可
- MyBatis批量添加、修改和删除
1.批量添加元素session.insert(String string,Object o) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...
- 【玩转cocos2d-x之三十九】Cocos2d-x 3.0截屏功能集成
3.0的截屏和2.x的截屏基本上同样.都是利用RenderTexture来处理,在渲染之前调用call函数,然后调用Cocos的场景visit函数对其进行渲染,渲染结束后调用end函数就可以.仅仅是3 ...
- Ios 调用Appstore 下载界面 [[UIApplication sharedApplication] openURL
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?mt=8&id=286274367 id = itunesconn ...
- HTML5中音频视频标签使用
HTML5中音频视频标签使用的最好方式 Html5中提供了<audio> <vedio>元素实现音频视频的引入播放 然而更好的方式
- Altium Designer 10 | 常用库及部分元件名中英文对照表
———————————————————————————————————————————— 常用库及部分元件名中英文对照表 - - - - - - - - - - - - - - - - - - - - ...
- 使用eclipse转换普通项目为web项目
1.在项目上,进入属性(properties) 2.左侧列表项目中选择“Project Facets”,在右侧选择“Dynamic Web Module”和"Java",(如果要修 ...
- Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFac
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...
- linux 查看cpu相关信息命令