[英]Python - make string equal length
I have a RNA sequence of varying length. 我有一个不同长度的RNA序列。 Max length of the sequence is 22. Some sequences are shorter.
序列的最大长度为22.一些序列较短。 So if a sequence is shorter then add "0" to the end of the line till the length becomes 22.
因此,如果序列较短,则在行的末尾添加“0”,直到长度变为22。
How to do it in python? 如何在python中做到这一点? this is my input
这是我的意见
AAGAUGUGGAAAAAUUGGAAUC AAGAUGUGGAAAAAUUGGAAUC
CAGUGGUUUUAUGGUAG CAGUGGUUUUAUGGUAG
CUCUAGAGGGUUUCUG CUCUAGAGGGUUUCUG
UUCAUUCGGC UUCAUUCGGC
and my expected ouput should be for example in the last line it does not contain 22 characters so i need to make it 22 by adding zero to it 我的预期输出应该是例如在最后一行它不包含22个字符所以我需要通过向它添加零来使它22
UUCAUUCGGC000000000000 UUCAUUCGGC000000000000
but as per your commands i am getting out put as AAGAUGUGGAAAAAUU 00000 the addtional characters used for justification came down and not in the same line 但是按照你的命令,我把它作为AAGAUGUGGAAAAAUU 00000用于理由的附加字符下来而不是在同一行
An alternative to @Aशwini चhaudhary's answer is: @Aशwiniचhaudhary的替代方案是:
s = '{0:0<22}'.format(s)
s = 'hello'
s = '{0:0<22}'.format(s)
>>> print s
hello00000000000000000
Or as शwini चhaudhary suggested, simply: 或者正如शwiniचhaudhary建议的那样,简单地说:
s = format(s, '0<22')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.