#语句
'''
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#1 为函数提供别名
from math import sqrt as Test
print(Test(4))
#2 序列解包
x,y,z = 1,23,4
print(x,y,z)
#3 数值交换
x,y = y, x
print(x, y, z)
#-------------------------输出结果----------------------------------#
"""
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
2.0
1 23 4
23 1 4
"""
#-----------------------------------------------------------------#
'''
"""
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#4
str = {'name':"zhangsan",'age':1,'addr':"haiding"}
key,value = str.popitem()#取出最后一个
print(key,value)
#-------------------------输出结果----------------------------------#
'''
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
addr haiding
'''
#-----------------------------------------------------------------#
"""
'''
#5嵌套代码块
name = input("please input name:")
if name.endswith('zhangsan'):
if name.startswith('Mr'):
print("Hello Mr")
elif name.startswith('Mrs'):
print("Hello Mrs")
else:
print("Hello World")
else:
print("Hello world ----")
'''
#-------------------------输出结果----------------------------------#
'''
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
please input name:Mr.zhangsan
Hello Mr
'''
#-----------------------------------------------------------------#
"""
#6 比较条件运算符(大于、小于、不等于) x is y x和y是同一个对象 两个列表值相等但是不一定是同一个对象
# 相等运算符
# is同一性运算符 in成员资格运算符 字符串和序列比较('adsasf' < 'faa' [1,2] < [3,4])
#示例:判断1-10之间的数字
num = int(input("请输入数字:"))
if num <= 10 and num > 0:
print("<= 10 Good")
else:
print("hehhe")
if 0 < num <= 10:
print("<= 10 Good")
else:
print("hehhe")
"""
#-------------------------输出结果----------------------------------#
'''
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
请输入数字:10
<= 10 Good
<= 10 Good
'''
#-----------------------------------------------------------------#
"""
#7 while循环
name = ''
while not name.strip() :#去掉空格
name = input("请输入姓名:")
print("Hello world %s" % name)
"""
#-------------------------输出结果----------------------------------#
'''
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
请输入姓名:
请输入姓名:
请输入姓名:zhang
Hello world zhang
'''
#-----------------------------------------------------------------#
"""
#8 For循环
words = [1,2,3,4,5,6,7,8,9]
for word in words:
print(word)
#迭代
for num in range(1,50):
print(num)
"""
"""
#9 循环遍历字典
d = {'name':"zhangsna",'age':45,'addr':"shanghai"}
for key in d:
print(key,":",d[key])
#items方法会将键值对做为元组返回
for key,value in d.items():
print(key,"--",value)
"""
#-------------------------输出结果----------------------------------#
'''
C:\python3.7\python.exe D:/Python-Test/qiubai/qiubai/Test4.py
name : zhangsna
age : 45
addr : shanghai
name -- zhangsna
age -- 45
addr -- shanghai
'''
#-----------------------------------------------------------------#
转载于:https://www.cnblogs.com/acer-haitao/p/7283774.html