Python经典入门100题 (51-60题)

题目地址: https://blog.csdn.net/weixin_41084236/article/details/81564963
转载请标注: https://blog.csdn.net/qq_43582207
代码编写过程中是自己发挥的,只代表其中一种方法,仅供学习参考
运行版本:Python3.7
作者:My apologize


实例054题,是借鉴这里的》》》https://blog.csdn.net/weixin_41084236/article/details/81564963

明日会专门出一期详细讲解python按位操作

实例051:按位与

# 实例051:按位与
# 题目 学习使用按位与 &

print(1&4);print(bin(1&4))

print(10001&10010)

print(212&215)

实例052:按位或

# 实例052:按位或
# 题目 学习使用按位或 | 。
print(bin(1)); print(bin(4))

print(1|4);print(bin(1|4));

实例053:按位异或

# 实例053:按位异或
# 题目 学习使用按位异或 ^ 。

print(0^0)
print(100^1111)
a=10
print(a^3)
print(a^3^7)

实例054:位取反、位移动

# 实例054:位取反、位移动
# 题目 取一个整数a从右端开始的4〜7位。
a=int(input('输入一个数字: '))
b=0                 #     0
b=~b                #     1
b=b<<4              # 10000
b=~b                #  1111
c=a>>4
d=c&b
print('a:',bin(a))
print('b:',bin(b))
print('c:',bin(c))
print('d:',bin(d))

实例055:按位取反

# 实例055:按位取反
# 题目 学习使用按位取反~。
print(55)
print(~55)
print(~~55)
print(bin(55), bin(~55))

实例056:画圈

# 实例056:画圈
# 题目 画图,学用circle画圆形。
import turtle
turtle.circle(50)


实例057:画线

# 实例057:画线
# 题目 画图,画直线。
import turtle

turtle.pensize(10)
turtle.fd(200)

实例058:画矩形

# 实例058:画矩形
# 题目 画图,学画方形。

import turtle
turtle.goto(100,0)
turtle.goto(100,-100)
turtle.goto(0,-100)
turtle.goto(0,0)

实例059:画图(丑)

# 实例059:画图(丑)
# 题目 画图,综合例子。

import turtle

turtle.fd(200)
turtle.right(90)
turtle.fd(250)
turtle.pu()
turtle.goto(200,-125)
turtle.pd()
turtle.goto(0,-125)
turtle.pu()
turtle.goto(100,-250)
turtle.pd()
turtle.goto(100,0)
turtle.pu()
turtle.goto(-50 ,-250)
turtle.pd()
turtle.goto(300,-250)

turtle.done()

实例060:字符串长度

# 实例060:字符串长度
# 题目 计算字符串长度。

a = 'dhiuehdu 15__67'
print(len(a))

=====================================================

如果觉得我的文章对你有帮助的,麻烦动动你的小手,关注支持一波!谢谢啦

########################################################

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Franda914

有钱的捧个钱场,没钱的点的赞

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值