栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

零基础自学python复习基础 运算符 数据类型 (四)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

零基础自学python复习基础 运算符 数据类型 (四)

前言

目录

一、数据类型

二、运算符

                1.算术运算符
                2.赋值运算符
                3.比较运算符
                4.逻辑运算符
                5.身份运算符
                6.成员运算符
                7.位运算符


                前言:数据类型、运算符零基础基础复习内容

一、数据类型
#str()类型
x = "不败的英雄"
x_1 = "铠甲勇士刑天后传"
print(x)
print(x_1)
#int()类型
h = 29
print(h)
#float()类型
h = 29.1
print(h)
#complex类型
h = 9j
print(h)
#list()类型
h = ["不败的英雄","Numpy"]
print(h)
#tuple()类型
x = ("说唱新时代","铠甲勇士刑天")
print(x)
#使用range()
h  = range(7)
print(h)
#dict ()类型
h = {"数组类型":"中文"}
print(h)
#set()类型
h = {"numpy","Mysql"}
print(h)
#frozenset()类型
x = ({"刑天","钉钉"})
print(x)
#bool()类型
x = True
print(x)
#bytes类型
x = b"python"
print(x)
#bytearray类型
x = bytearray (4)
print(x)
#memoryview类型
x = memoryview (bytes(9))
print(x)

#str()类型
x = str("不败的英雄")
x_1 = "铠甲勇士刑天后传"
print(x)
print(x_1)
#int()类型
h = int(29)
print(h)
#float()类型
h =float( 29.1)
print(h)
#complex类型
h = complex(9j)
print(h)
#list()类型
h =list (("不败的英雄","Numpy"))
print(h)
#tuple()类型
x = tuple(("说唱新时代","铠甲勇士刑天"))
print(x)
#使用range()
h  = range(7)
print(h)
#dict ()类型
h = dict(铠甲勇士刑天 = 60,铠甲勇士 = 52)
print(h)
#set()类型
h = set(("numpy","Mysql"))
print(h)
#frozenset()类型
x = frozenset(("刑天","钉钉"))
print(x)
#bool()类型
x = bool(True)
print(x)
#bytes类型
x = bytes(9)
print(x)
#bytearray类型
x = bytearray (4)
print(x)
#memoryview类型
x = memoryview (bytes(9))
print(x)
二、运算符

        1.算术运算符

h = 7
f = 4
#加法运算
print(f+h)
#减法运算
print(h-f)
#乘法运算
print(h*f)
#除法运算
print(h/f)
#取模运算
print(h%f)
#幂运算
print(h**f)
# 整除运算符
print(h//f)


        2.赋值运算符

h = 7
print(h)
# 加法赋值运算
h += 4
print(h)
#减法赋值运算
h -= 4
print(h)
#乘法赋值运算
h *= 7
print(h)
#除法赋值运算
h /= 4
print(h)
#取模赋值运算
h %= 3
print(h)
#按位与计算整数的结果
print(str(2&9))
#按位或计算整数的结果
print(str(4 | 7))
#按位异或计算整数的结果
print(str(4^ 4))
#按位取反计算整数的结果
print(str(~456))
#右移动运算
print(8>>7)
#左移动运算
print(3<< 9)
#qq密码
QQPassword = 123456789
#加密差数
key = 4
#输出原密码
print(QQPassword)
#将原密码,左移生成新的数字
QQPassword = QQPassword << key
#输出加密后的密码
print(QQPassword )
#将新密码右移动,解密密码
QQPassword  =  QQPassword >> key
#输出解密密码
print(QQPassword )


        3.比较运算符

#等于
k = 4
f = 5
print(k == f)
#不等于
print(k != f)
#大于
print(k > f)
#小于
print(f < f)
# 大于或等于
print(f >= k)
#小于或等于
print(k <=  f)


        4.逻辑运算符

#and
#如果两个语句都为真,则返回 True。
x = 7
k = 4
g = 9
if x > k and x > g:
    print("答案")
#or
#如果其中一个语句为真,则返回 True。
if g > k or g > x:
    print("运算符")
#not
#反转结果,如果结果为 true,则返回 False
if not(k > x and k > x):
    print("not")


        5.身份运算符

#is
#如果两个变量是同一个对象,则返回 true。
k = 4
g = 9
print(k is g)
#is not
#如果两个变量不是同一个对象,则返回 true。
if k is not g:
    print("Windows")


        6.成员运算符

#in
#如果对象中存在具有指定值的序列,则返回 True。
k = [1,2,3,4,5,6,7]
g = 7
if g in k:
    print("放弃不难")
#not in
# 如果对象中不存在具有指定值的序列,则返回 True。
e = 10
if e not in k:
    print("百度")


        7.位运算符

#按位与计算整数的结果
print(str(2&9))
#按位或计算整数的结果
print(str(4 | 7))
#按位异或计算整数的结果
print(str(4^ 4))
#按位取反计算整数的结果
print(str(~456))
#右移动运算
print(8>>7)
#左移动运算
print(3<< 9)
#原密码
pwd = 123456789
#加密数字
key = 4
#输出原始密码
print(pwd)
#向左移动加密
pwd = pwd << key
#输出加密密码
print(pwd)
#向右移动解密密码
pwd = pwd >> key
#输出解密密码
print(pwd)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/915805.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号