python随笔01
1、Python种类:
JPython,IronPython,JavaScriptPython,RubyPython,pypy。
2、Python下载:
python2: 在更新,在慢慢向python3转换。
python3: 也在更新
3、input的用法:
永远等待,直到用户输入了值,就会将输入的值赋值给一个变量(变量由字母、数字、下划线组成。不能数字开头,不能是关键字--'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield')
4、字符串:
"string" , 'string' ,"""string""",'''string'''。
加法--拼接。
乘法--"你好"*10 ,让"你好"出现10次。
5、条件语句--代码块需要缩进,每一个代码块的缩进长度需要一样,建议缩进4个空格(或者按tab),else if写成elif。
if 条件: print('ok') elif 条件: print('error') else print('end')
if 条件: pass(如果什么都不处理,需要缩进写pass) else print('end)
6、while循环
while 条件: print('ok') print('end')
7、练习
a.输出1 2 3 4 5 6 8 9 10
n=1; while n<11: if n==7: pass else: print(n) n=n+1 print ('---end---')
b.1-100的所有数的和
sum=0 m=0 while m<101: sum+=m m+=1 print(sum)
c.输出 1-100 内的所有奇数
c = 1
while c < 101:
temp = c % 2
if temp == 0:
pass
else:
print(c)
c = c + 1
posted on 2018-03-25 23:08 ForrestHope 阅读(111) 评论(0) 收藏 举报
浙公网安备 33010602011771号