19.Python3-简单实例

题记

        python3简单实例

打印字符串

print("Hello, world!")

输出变量值

i = 256*256
print('i 的值为:', i)

数学运算

x = 3
y = 2
z = x + y
print(z)

定义列表

my_list = ['1', '2', '3']
print(my_list[0]) # 输出 "1"
print(my_list[1]) # 输出 "2"
print(my_list[2]) # 输出 "3"

for循环

for i in range(5):
    print(i)

if语句

x = 6
if x > 10:
    print("x 大于 10")
else:
    print("x 小于或等于 10")

斐波那契数列

#!/usr/bin/python3
 
# Fibonacci series: 斐波纳契数列
# 两个元素的总和确定了下一个数
a, b = 0, 1
while b < 10:
    print(b)
    a, b = b, a+b

        for循环:

n = 10
a, b = 0, 1
for i in range(n):
    print(b)
    a, b = b, a + b

end关键字

 # Fibonacci series: 斐波纳契数列
# 两个元素的总和确定了下一个数
a, b = 0, 1
while b < 1000:
    print(b, end=',')
    a, b = b, a+b

后记

        觉得有用可以点赞或收藏!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
“ class MyDialog21(wx.Dialog): def __init__(self, parent): wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"派送员信息", pos=wx.DefaultPosition, size=wx.Size(400, 415), style=wx.DEFAULT_DIALOG_STYLE) self.Center() self.panel = wx.Panel(self) self.panel.SetBackgroundColour('white') wx.StaticText(self.panel, -1, "菜品名称:", (20, 20)) self.t1 = wx.TextCtrl(self.panel, pos=(90, 20), size=(120, 25)) # btn = wx.Button(parent=self.panel, label="查询", pos=(240, 20), size=(70, 25)) # btn.Bind(wx.EVT_BUTTON, self.find) wx.StaticText(self.panel, -1, "派送员编号", (20, 60)) wx.StaticText(self.panel, -1, "派送员姓名", (120, 60)) wx.StaticText(self.panel, -1, "派送员电话", (220, 60)) def OnClick(self, event): dialog21 = MyDialog21(None) btn = wx.Button(parent=dialog21.panel, label="查询", pos=(240, 20), size=(70, 25)) btn.Bind(wx.EVT_BUTTON, dialog21.find) dialog21.ShowModal() def find(self, event): conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='wm', charset='utf8') cursor = conn.cursor() try: sql = "select * from courier" cursor.execute(sql) rs = cursor.fetchall() h = 80 for row in rs: if row[3] == self.t1.GetValue(): h = h + 20 courier_id = row[0] courier_name = row[1] courier_phone = row[2] wx.StaticText(self.panel, -1, courier_id, (20, h)) wx.StaticText(self.panel, -1, courier_name, (120, h)) wx.StaticText(self.panel, -1, courier_phone, (220, h)) except: conn.rollback() finally: cursor.close() conn.close()”逐行解释代码
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值