如果你是零基础入门 Python 的话,建议初学者至少达到两个目标: 会用,理解。
会用
通过 Python 入门教程,学习 Python 的语法,熟悉 Python 标准库的使用。
目前 Python 官方已经发布了中文版的官方教程,降低了学习 Python 的门槛。建议初学者一开始直接从 Python 官方教程开始学习 Python。
通过 Python 官方教程,学习 Python 的语法,熟悉 Python 标准库的使用。
目前 Python 官方已经发布了中文版的官方教程,降低了学习 Python 的门槛。建议初学者一开始直接从 Python 官方教程开始学习 Python。
理解
程序这个东西,即使你一知半解,也是可以跑的通的。但是这样的学习效果不是我们想要的。程序能运行,不代表你学会了。所以,不管是学习 Python,还是其他语言,理解程序是最重要的,理解了程序,才能学会。
初学者可以通过 Python Tutor ,直接在 Web 浏览器中编写 Python 代码,可视化地运行程序。
通过可视化的程序运行步骤,来帮助初学者理解程序,加深对代码的思考。
如果你觉得看文章学习枯燥无味,还可以找 Python 的视频教程来学习。
我这里有很多的python干货资料,需要的可以找我来拿
let exec_throw stk pre_state (block : Llair.block) exc =
let func = block.parent in
[%Trace.call fun {pf} -> pf "from %a" Llair.Reg.pp func.name.reg]
;
let unwind formals scope from_call state =
Dom.retn formals (Some func.fthrow) from_call
(Dom.post scope from_call state)
in
( match Stack.pop_throw stk ~unwind ~init:pre_state with
| Some (from_call, retn_site, stk, unwind_state) ->
let fthrow = func.fthrow in
let exit_state =
Dom.exec_move unwind_state (IArray.of_ (fthrow, exc))
in
let post_state = Dom.post func.locals from_call exit_state in
let retn_state =
Dom.retn func.formals func.freturn from_call post_state
in
exec_jump stk retn_state block retn_site
| None -> Work.skip )
|>
[%Trace.retn fun {pf} _ -> pf ""]
let exec_skip_func :
Stack.t
-> Dom.t
-> Llair.block
-> Llair.Reg.t option
-> Llair.jump
-> Work.x =
fun stk state block areturn return ->
Report.unknown_call block.term ;
let state = Option.fold ~f:Dom.exec_kill ~init:state areturn in
exec_jump stk state block return
let exec_term :
exec_opts
-> Llair.program
-> Stack.t
-> Dom.t
-> Llair.block
-> Work.x =
fun opts pgm stk state block ->
"@[<2>exec term@\n@[%a@]@\n%a@]" Dom.pp state Llair.Term.pp block.term] ;
match block.term with
| Switch {key; tbl; els} ->
IArray.fold tbl
~f:(fun x (case, jump) ->
match Dom.exec_assume state (Llair.Exp.eq key case) with
| Some state -> exec_jump stk state block jump |> Work.seq x
| None -> x )
~init:
( match
Dom.exec_assume state
(IArray.fold tbl ~init:Llair.Exp.true_
~f:(fun b (case, _) ->
Llair.Exp.and_ (Llair.Exp.dq key case) b ))
with
| Some state -> exec_jump stk state block els
| None -> Work.skip )
| Iswitch {ptr; tbl} ->
IArray.fold tbl ~init:Work.skip ~f:(fun x (jump : Llair.jump) ->
match
Dom.exec_assume state
(Llair.Exp.eq ptr
(Llair.Exp.label
~parent:(Llair.Reg.name jump.dst.parent.name.reg)
~name:jump.dst.lbl))
with
| Some state -> exec_jump stk state block jump |> Work.seq x
| None -> x )
| Call ({callee; actuals; areturn; return} as call) -> (
let lookup name =
Option.to_list (Llair.Func.find pgm.functions name)
in
let callees, state = Dom.resolve_callee lookup callee state in
match callees with
| [] -> exec_skip_func stk state block areturn return
| callees ->
List.fold callees ~init:Work.skip ~f:(fun x callee ->
( match
Dom.exec_intrinsic ~skip_throw:opts.skip_throw state
areturn callee.name.reg actuals
with
| Some None ->
Report.invalid_access_term
(Dom.report_fmt_thunk state)
block.term ;
Work.skip
| Some (Some state) when Dom.is_false state -> Work.skip
| Some (Some state) -> exec_jump stk state block return
| None when Llair.Func.is_undefined callee ->
exec_skip_func stk state block areturn return
| None ->
exec_call opts stk state block {call with callee}
(Domain_used_globals.by_function opts.globals
callee.name.reg) )
|> Work.seq x ) )
| Return {exp} -> exec_return ~opts stk state block exp
| Throw {exc} ->
if opts.skip_throw then Work.skip
else exec_throw stk state block exc
| Unreachable -> Work.skip