欢迎来到天天文库
浏览记录
ID:20695640
大小:456.05 KB
页数:84页
时间:2018-10-15
《python入门教程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Python入门教程1----PythonSyntax1Python是一个高效的语言,读和写的操作都是很简单的,就像普通的英语一样2Python是一个解释执行的语言,我们不需要去编译,我们只要写出代码即可运行3Python是一个面向对象的语言,在Python里面一切皆对象4Python是一门很有趣的语言5变量:一个变量就是一个单词,只有一个单一的值练习:设置一个变量my_variable,值设置为10 [cpp] #Writeyourcodebelow! my_variable=10 3第三节 1Python里面有三种数据类型interage,floats,boolean
2、s 2Python是一个区分大小写的语言 3练习 1把变量my_int值设置为7 2把变量my_float值设置为1.23 3把变量my_bool值设置为true[python] #Setthevariablestothevalueslistedintheinstructions! my_int=7 my_float=1.23 my_bool=True 6Python的变量可以随时进行覆盖 2练习:my_int的值从7改为3,并打印出my_int [python] #my_intissetto7below.Whatdoyouthink #willha
3、ppenifweresetitto3andprinttheresult? my_int=7 #Changethevalueofmy_intto3online8! my_int=3 #Here'ssomecodethatwillprintmy_inttotheconsole: #Theprintkeywordwillbecoveredindetailsoon! printmy_int 7Pyhton的声明和英语很像8Python里面声明利用空格在分开 3练习:查看以下代码的错误[python] defspam(): eggs=12 returneggs prin
4、tspam() 9Python中的空格是指正确的缩进 2练习:改正上一节中的错误[python] defspam(): eggs=12 returneggs printspam() 10Python是一种解释执行的语言,只要你写完即可立即运行 2练习:设置变量spam的只为True,eggs的值为False [python] spam=True eggs=False 11Python的注释是通过“#”来实现的,并不影响代码的实现 2练习:给下面的代码加上一行注释[python] #thisisacommentsforPython mysterious
5、_variable=42 12Python的多行注释是通过“"""""" ”来实现的 2练习:把下面的代码加上多行[python] """ thisisaPythoncourse """ a=5 13Python有6种算术运算符+,-,*,/,**(幂),% 2练习:把变量count_to设置为1+2[python] #Setcount_toequalto1plus2online3! count_to=1+2 printcount_to 14Python里面求x^m,写成x**m 2练习:利用幂运算,把eggs的值设置为100[python] #Seteggsequa
6、lto100usingexponentiationonline3! eggs=10**2 printeggs 1练习: 1写一行注释 2把变量monty设置为True 3把变量python值设置为1.234 4把monty_python的值设置为python的平方[python] #thisisaPython monty=True python=1.234 monty_python=python**2 Python入门教程2----TipCalculator1把变量meal的值设置为44.50[python] #Assignthevariablemealt
7、hevalue44.50online3! meal=44.50 1把变量tax的值设置为6.75% [python] meal=44.50 tax=6.75/100 1设置tip的值为15% [python] #You'realmostthere!Assignthetipvariableonline5. meal=44.50 tax=0.0675 tip=0.15 1把变量meal的值设置为meal+meal*tax[python] #Reassignme
此文档下载收益归作者所有