码迷,mamicode.com
首页 > 其他好文 > 详细

for循环每次取出一个字符(不是字节)

时间:2016-12-16 07:44:51      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:env   for   取出   bin   code   hex   blog   pytho   log   

python3.5 for循环每次取出一个字符(不是字节)

#!/usr/bin/env python
# -*- coding:utf-8 -*-

my_str = "我是哈哈"
for i in my_str:
    my_bytes = bytes(i, utf-8)
    print(my_bytes)
    my_bytes = bytes(i, gbk)
    print(my_bytes)

for i in my_str:
    my_bytes = bytes(i, utf-8)
    for b in my_bytes:
        print(hex(b))
        print(bin(b))
        print(oct(b))
        print(b)

 

for循环每次取出一个字符(不是字节)

标签:env   for   取出   bin   code   hex   blog   pytho   log   

原文地址:http://www.cnblogs.com/y990441/p/6185412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!