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

Python--第一天作业

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

Python--第一天作业

1.定义变量:
两种方式:
第一种:显式的定义: int_data = 1
int_data = 1
print(int_data, type(int_data))

第二种:使用类型转换形式定义: int_data = int(): 除了None之外的
int, float, complex, bool, None, bytes, str, tuple
int_data = 1
int_data = int(1)
print(int_data, type(int_data))

f = 2.2
f = float(2.2)
print(f, type(f))

com = 2+3j
com = complex(2+3j)
print(com, type(com))

b = True
b = bool(True)
print(b, type(b))

n = None
print(n, type(n))

by = b"1234"
by = bytes(b"1234")
print(by, type(by))

tuple_data = (1, 2, 4, 6)
print(tuple_data, type(tuple_data))

str_data = “happy”
str_data =str(“happy”)
print(str_data, type(str_data))

2.list列表:
以两种方式获取到list的源码
第一种:help(list)
第二种:按住ctrl键鼠标点击list()

3.print函数的使用:
1)打印多个内容,输出的格式: 多个内容用&连接
print (0, 1, 2, 3, 4, sep="&")

2)多个print语句,输出不换行,且在结尾加上ThisisEnding
print(1, 2, 3, end=“ThisisEnding”)
print(4, 5)

4…字节和字符串转换:
“鸥鹏” 转换成 字节
str_data = “欧鹏”
bytes_data = bytes(str_data, encoding=“utf-8”)
print (bytes_data, type(bytes_data))

字节转换成字符串
bytes_data = b’xe6xacxa7xe9xb9x8f’
str_data = str(bytes_data, encoding=“utf-8”)
print(str_data, type(str_data))

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

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

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