1.定义变量:
两种方式:
第一种:显式的定义: int_data = 1
第二种:使用类型转换形式定义: int_data = int(): 除了None之外的
int, float, complex, bool, None, bytes, str, tuple
2.list列表:
以两种方式获取到list的源码
3.print函数的使用:
(1).打印多个内容,输出的格式: 多个内容用&连接
(2).多个print语句,输出不换行,且在结尾加上ThisisEnding
举例: print()
print()
4.字节和字符串转换:
“鸥鹏” 转换成 字节
字节转换成字符串
# 类型转化
#1、定义变量:
# 两种方式:
# 第一种:显式的定义:
int_data = 1
print(int_data, type(int_data))
float_data = 2.2
print(float_data, type(float_data))
complex_data = 3 + 4j
print(complex_data, type(complex_data))
bytes_data = b"456"
print(bytes_data, type(bytes_data))
# 第二种:使用类型转换形式定义:
int_data = int(1)
print(int_data, type(int_data))
float_data = float(2.2)
print(float_data, type(float_data))
complex_data = complex(3, 4)
print(complex_data, type(complex_data))
# True, False
bool_data = bool(True)
print(bool_data, type(bool_data))
# bytes 字节 b''/ b" "
bytes_data = bytes(b"456")
print(bytes_data, type(bytes_data))
# str
str_data = str("a")
print(str_data, type(str_data))
# tuple
tuple_data = (1, 2, 3, 4)
print(tuple_data, type(tuple_data))
"""
3、以两种方式获取到list的源码
(1)ctrl+单击list
(2)输入help(list)
"""
#4.print函数的使用
# 1、打印多个内容,输出的格式: 多个内容用&连接
print(1, 2, 3, 4, 5, 6, sep = '&')
# 2、多个print语句,输出不换行,且在结尾加上ThisisEnding
print(1, 2, 3, 4, end=' ThisisEnding ')
print(5, 6, 7)
#5、字节和字符串转换:
# "鸥鹏" 转换成 字节
str_data = "欧鹏"
bytes_data = bytes(str_data, encoding="utf-8")
print(bytes_data, type(bytes_data))
# 字节转换成字符串
bytes_data = b'\xe6\xac\xa7\xe9\xb9\x8f'
str_data = str(bytes_data, encoding="utf-8")
print(str_data, type(str_data))
运行结果
1 <class 'int'>
2.2 <class 'float'>
(3+4j) <class 'complex'>
b'456' <class 'bytes'>
1 <class 'int'>
2.2 <class 'float'>
(3+4j) <class 'complex'>
True <class 'bool'>
b'456' <class 'bytes'>
a <class 'str'>
(1, 2, 3, 4) <class 'tuple'>
1&2&3&4&5&6
1 2 3 4 ThisisEnding 5 6 7
b'\xe6\xac\xa7\xe9\xb9\x8f' <class 'bytes'>
欧鹏 <class 'str'>
Process finished with exit code 0