• <i id='GXMV2'><tr id='GXMV2'><dt id='GXMV2'><q id='GXMV2'><span id='GXMV2'><b id='GXMV2'><form id='GXMV2'><ins id='GXMV2'></ins><ul id='GXMV2'></ul><sub id='GXMV2'></sub></form><legend id='GXMV2'></legend><bdo id='GXMV2'><pre id='GXMV2'><center id='GXMV2'></center></pre></bdo></b><th id='GXMV2'></th></span></q></dt></tr></i><div id='GXMV2'><tfoot id='GXMV2'></tfoot><dl id='GXMV2'><fieldset id='GXMV2'></fieldset></dl></div>

      1. <tfoot id='GXMV2'></tfoot>
          <bdo id='GXMV2'></bdo><ul id='GXMV2'></ul>

        <small id='GXMV2'></small><noframes id='GXMV2'>

      2. <legend id='GXMV2'><style id='GXMV2'><dir id='GXMV2'><q id='GXMV2'></q></dir></style></legend>
      3. 我怎样才能增加一个字符?

        时间:2023-08-06
            <tbody id='fghg3'></tbody>
          <i id='fghg3'><tr id='fghg3'><dt id='fghg3'><q id='fghg3'><span id='fghg3'><b id='fghg3'><form id='fghg3'><ins id='fghg3'></ins><ul id='fghg3'></ul><sub id='fghg3'></sub></form><legend id='fghg3'></legend><bdo id='fghg3'><pre id='fghg3'><center id='fghg3'></center></pre></bdo></b><th id='fghg3'></th></span></q></dt></tr></i><div id='fghg3'><tfoot id='fghg3'></tfoot><dl id='fghg3'><fieldset id='fghg3'></fieldset></dl></div>

          <small id='fghg3'></small><noframes id='fghg3'>

              <bdo id='fghg3'></bdo><ul id='fghg3'></ul>
            • <tfoot id='fghg3'></tfoot>

              <legend id='fghg3'><style id='fghg3'><dir id='fghg3'><q id='fghg3'></q></dir></style></legend>

                  本文介绍了我怎样才能增加一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 Python 的新手,来自 Java 和 C.如何增加 char?在 Java 或 C 中,chars 和 int 实际上是可以互换的,并且在某些循环中,能够对 chars 进行增量以及按 chars 索引数组对我非常有用.

                  I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars.

                  如何在 Python 中做到这一点?没有传统的 for(;;) 循环器已经够糟糕了 - 有什么方法可以实现我想要实现的目标,而无需重新考虑我的整个策略?

                  How can I do this in Python? It's bad enough not having a traditional for(;;) looper - is there any way I can achieve what I want to achieve without having to rethink my entire strategy?

                  推荐答案

                  在 Python 2.x 中,只需使用 ordchr 函数:

                  In Python 2.x, just use the ord and chr functions:

                  >>> ord('c')
                  99
                  >>> ord('c') + 1
                  100
                  >>> chr(ord('c') + 1)
                  'd'
                  >>> 
                  

                  Python 3.x 使这更加有条理和有趣,因为它在字节和 unicode 之间有明显的区别.默认情况下,字符串"是 unicode,因此上述方法有效(ord 接收 Unicode 字符,chr 生成它们).

                  Python 3.x makes this more organized and interesting, due to its clear distinction between bytes and unicode. By default, a "string" is unicode, so the above works (ord receives Unicode chars and chr produces them).

                  但是如果你对字节感兴趣(比如处理一些二进制数据流),事情就更简单了:

                  But if you're interested in bytes (such as for processing some binary data stream), things are even simpler:

                  >>> bstr = bytes('abc', 'utf-8')
                  >>> bstr
                  b'abc'
                  >>> bstr[0]
                  97
                  >>> bytes([97, 98, 99])
                  b'abc'
                  >>> bytes([bstr[0] + 1, 98, 99])
                  b'bbc'
                  

                  这篇关于我怎样才能增加一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Python 中将字符转换为整数,反之亦然? 下一篇:struct.error:结构格式中的错误字符

                  相关文章

                  最新文章

                    <legend id='y8Bre'><style id='y8Bre'><dir id='y8Bre'><q id='y8Bre'></q></dir></style></legend>

                      <tfoot id='y8Bre'></tfoot>

                    1. <i id='y8Bre'><tr id='y8Bre'><dt id='y8Bre'><q id='y8Bre'><span id='y8Bre'><b id='y8Bre'><form id='y8Bre'><ins id='y8Bre'></ins><ul id='y8Bre'></ul><sub id='y8Bre'></sub></form><legend id='y8Bre'></legend><bdo id='y8Bre'><pre id='y8Bre'><center id='y8Bre'></center></pre></bdo></b><th id='y8Bre'></th></span></q></dt></tr></i><div id='y8Bre'><tfoot id='y8Bre'></tfoot><dl id='y8Bre'><fieldset id='y8Bre'></fieldset></dl></div>

                      • <bdo id='y8Bre'></bdo><ul id='y8Bre'></ul>

                      <small id='y8Bre'></small><noframes id='y8Bre'>