【Python基础到进阶】Python的一些特殊用法总结

Python的一些特殊用法总结

格式化打印输出

values=input(">>>")
l=values.split(",")
t=tuple(l)
print(f"List of values : {l}")
print(f"Tuple of values : {t}")
x = {'name':"xiong","age":26}
print(f"{x}")

'''
>>>12,56,48,98,36,22
List of values : ['12', '56', '48', '98', '36', '22']
Tuple of values : ('12', '56', '48', '98', '36', '22')
{'name': 'xiong', 'age': 26}
'''

一行代码实现的for循环

n=int(input(">>>"))
d={x:x*x for x in range(1,n+1)}
print(d)

"""
>>>8
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
"""

猜你喜欢

转载自www.cnblogs.com/XJT2018/p/11024469.html