Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
数据处理
209
12-6:位级整数运算符
运算符 描述 示例 十进制结果 二进制结果
&
x & y 1 0b0001
|
x | y 5 0b0101
^
异或
x ^ y 4 0b0100
~
取反
~x -6
取决于
int
类型大小
<<
左移
x << 1 10 0b1010
>>
右移
x >> 1 2 0b0010
这些运算符类似于第
8
章中的集合运算符。
&
运算符可以返回两个操作数中相同的位。
|
可以返回两个操作数中为
1
的位。
^
可以返回仅在一个操作数中为
1
的位。
~
可以将单个
操作数的所有位取反,这同时也颠倒了操作数的符号,因为现代计算机使用的是
2
的补码
two
s complement
,整数的最高位代表其符号(
0
为正,
1
为负)。
<<
>>
运算符操作数
可以向左或向右移动指定位数,左移一位相当于将操作数乘以
2
,右移一位相当于将操作
数除以
2
12.4
珠宝类比
Unicode
字符串就像一只迷人的手镯,字节则像是一串串的珠子。
12.5
后续内容
13
章会介绍另一个实用主题:如何处理日期和时间。
12.6
练习
1.
创建
Unicode
字符串
mystery
,为其赋值
'\U0001f984'
。打印出
mystery
及其
Unicode
名称。
2.
使用
UTF-8
,将
mytery
编码后存入
bytes
类型的变量
pop_bytes
。打印出
pop_bytes
3.
使用
UTF-8
pop_bytes
解码后存入字符串变量
pop_string
。打印出
pop_string
pop_string
是否等于
mystery
4.
在处理文本时 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
量子计算机编程:从入门到实践

量子计算机编程:从入门到实践

Eric R. Johnston, Nicholas Harrigan, Mercedes Gimeno-Segovia
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787115586223