python基础语法复习

二、数据类型、类型转换、字典输出、推导式

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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱发呆的光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值