零基础自学Python复习基础 每日一练 【一个小练习

家电修理 2023-07-16 19:17www.caominkang.com电器维修

前言

目录

一、一个小时练习


                        1.format、carname 、model
                        2.print()
                        3.转义字符
                        4.变量
                        5.数据类型转换


        前言  零基础自学Python复习基础 每日一练  一个小时练习  慢即是快   少即是多 。

一、一个小时练习


                        1.format、carname 、model

#format()
k = 2022
d = 52
t = "铠甲勇士{1}集,搜狗版本{0}年"
print(t.format(k,d))
#{:.2f}
k = 2.40000000000
g = "分数{:.2f}"
print(g.format(k))
#索引
k = 52
f = 52
 = 60
q = "铠甲勇士全集{0},铠甲勇士刑天全集{2},迪迦奥特曼全集{1}"
print(q.format(k,f,))
#命名索引
k = "铠甲勇士{carname}, 铠甲勇士刑天{model}"
print(k.format(carname = "52集",model = "60集"))
#占位符
y = 52
x = 52
d = 60
kjys = "铠甲勇士{0}集、迪迦奥特曼{1}集、铠甲勇士刑天{2}"
print(kjys.format(y,x,d))
#命名索引
kjys = "铠甲勇士{carname}集、铠甲勇士刑天{model}集"
print(kjys.format(carname = "52",model = "60"))
#二位小数点 {:.2f}
k = 52.00000
t = 60.00000
kjys = "铠甲勇士{0:.2f}集、铠甲勇士刑天{1:.2f}"
print(kjys.format(k,t))


                        2.print()

#print()输出函数
#数字
print(40)
print(90)
print(40)
#字符串
print("n铠甲勇士","n拿瓦","n雪獒")
print('t刑天铠甲合体','tpython','t2022')
print('tnstr','tnint','tntuple','tnset')
#表达式
print(4+5)
print(4)
k = open("D:/122/kjys.txt",'')
print("李白",file = k)
k.close()


                        3.转义字符

#转义字符
print("setnint")
print("ttuple")
print("ntfor")
print("rhile")
print("breakbpython format")
print("https:\\.bilibili.")
print(r"https:\\.bilibili.")
print('python:'set()'')
print('python:'dict()'')


                        4.变量

# 变量
k  = 7
print(id(k),type(k),k)
k = 7
k = 9
print(id(k),type(k),k)
k_1 ="id(),type(),popitem()"
# 1_k = "id(),type(),popitem()"
#k k = "id(),type(),popitem()"
#set = "id(),type(),popitem()"
#type = "id(),type(),popitem()"
print(id(k_1),type(k_1),k)


                        5.数据类型转换

数据类型转换
#int()、str()、float()、十进制、八进制(0o)、二进制(0b)、十六进制(0x)
print("十进制",400)
print("二进制",0b010101111101010111010)
print("八进制",0o76543210)
print("十六进制",0xAEDF141)
k = 201
h = 2.1
p = "4.1"
e = "李白"
print(type(k),type(h),type(p),type(e))
#变量转换成int()类型
k = 201
h = 2.1
 = -4
# p = "4.1"
# e = "李白"
print(int(k),type(k),int(h),type(h),int(),type())
#将变量转换成str()类型
k = 201
h = 2.1
 = -4
p = "4.1"
e = "李白"
print(str(k),type(k),str(h),type(h),str(),type(),str(p),type(p),str(e),type(e))
#将变量转换成float()类型
k = 201
h = 2.1
 = -4
p = "4.1"
# e = "李白"
print(float(k),type(k),float(h),type(h),float(),type(),float(p),type(p))

Copyright © 2016-2025 www.caominkang.com 曹敏电脑维修网 版权所有 Power by