二、数据类型、类型转换、字典输出、推导式
a=1;b=1.0;c="python";d=True;e=3+5j;g=(11,22);h={'光','爱发呆'};i={'1':'为什么学python','2':'python简洁呀'}
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(h))
print(type(i))
f=float(a) #数据类型强制转换
print(type(f))
total=a+b #四则运算符号为+-*/ % 取余 ** 乘方
print(i['1']) #字典输出
interests=['Footboll','Table Tennis','badminton']
N_interest=[interest.upper()for interest in interests]
print(N_interest)
newdict = {key:len(key) for key in interests}
print(interests)
square={i**2for i in range(1,5)}
print(square)
print(a+c) #字符类型不一运算结果会报错
G:\py-project\venv\Scripts\python.exe G:/py-project/mstduy/test/2.py
Traceback (most recent call last):
File "G:\py-project\mstduy\test\2.py", line 20, in <module>
print(a+c) #字符类型不一运算结果会报错
TypeError: unsupported operand type(s) for +: 'int' and 'str'
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
<class 'complex'>
<class 'set'>
<class 'dict'>
<class 'float'>
为什么学python
['FOOTBOLL', 'TABLE TENNIS', 'BADMINTON']
['Footboll', 'Table Tennis', 'badminton']
{16, 1, 4, 9}
进程已结束,退出代码为 1