日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python学习 第一篇 基础

發布時間:2023/12/19 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python学习 第一篇 基础 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上周報名了reboot python 課程,終于下決心要把python 搞好了,希望自己能堅持下來,并得到自己想要的成績

#coding:utf-8 #呵呵 #print?'hello?world' #x='hello?world' #print?x #x=raw_input('hello?world') #print?x #int #print?2+3 #print?1+2*3 #print?8/3 #print?8/3.0 #print?8%3 #str??單雙引號無卻別 print?'hello?world' print?"hello?world" print?"I'am?pythoner" print?'I\'am?pythoner' #三個單引號?起聲明作用 print?''' this? is? atest ''' #字符串拼接 print?'hello?'+'reboot' print?'hello?'*2 #字符串格式化 #數字(0,?1,?...)即代表format()里面的元素,?所以可以使用"."調用元素的方法; x='fujinzhou' y=22 h='good' print?'Hi?%s?I?am?%d?years?old?,You?are?very?%s'%(x,y,h) print?'Hi?'+?x?+',You?are?very?'+?h?+''? print?('Hi?{0}?I?am?{1}?years?old,You?are?very?{2}!'.format(x,y,h)) #布爾值?True?False??與或非? #and #兩邊都是真,才是真 #print?True?and?True #print?2>3?and?3>2 #or?或?,兩種情況只要有一種情況 #print?True?or?False #not?非 #print?not?False #print?not?True #流程控制 #if?True?or?False: #????是True?就執行這段代碼 if?2<3?or?5<4: print?'condition?is?True' else: print?'condition?is?False' name='reboot' age=20 if?name=='reboot': if?age>10: print?'you?are?%s?years?old'%(age) print?'condition?is?reboot' else: print?'condition?is?False' #while?循環 #while?情況1: #里面的代碼會一直執行,直到情況1是false #i=0 #while?i<20: #print?i #i+=1 #print?'while?is?end' #用戶一直輸入數字,當輸入0時。終止并輸出數字之和 count=0 while?True:i=int(raw_input('please?inut?your?number:'))count?+=iif?i==0:print?countbreak; count=0 y=raw_input('please?input?a?number') while?int(y)!=0:count?=count+int(y)y=raw_input('please?input?a?number') print?'the?total?is?%d'%(count) #用戶一直輸入數字,當輸入為空時。終止并輸出平均值 count=0 total=0 y=raw_input('please?input?a?number') while?y:count?=count+int(y)y=raw_input('please?input?a?numbers:')total+=1 print?'the?total?is?%s'%(count/total) #for?循環?專門針對list?dict等結構 #arr=['1','2','three'] #for?i?in?arr: #??print?i #找出列表中js出現的次數 #num=0 #list1=['c','python','js','node','java','js','ruby'] #for?i?in?list1: #if?i?=='js': #????????????num+=1 #print?num #numlist=[1,2,3,2,12,3,1,3,21,2,2,3,4111,22,3333,444,111,4,5,777,65555,45,33,45] #max1=0 #max2=0 #for?i?in?numlist: #if?max1<i: #max1=i #for?i?in?numlist: #if?max1==i: #continue #if?max2<i: #max2=i #print?max1,max2 #i=0 #while?True: #if?i?>10: #break #print?i #i+=1 #arr=['c','python','js','node'] #for?i?in?arr: #if?i=='js': #continue #print?i #d?={'name':'reboot','age':50} #print?d['name']?#根據key?獲取?value #d['age']=50??#修改值 #print?d #d['newkey']='key1'?#增加新值 #print?d #total=0 b={} a=['C','js','python','js','css','js','html','node','js','python','js','css','js','html','node','js','python','js','css','js'] for?i?in?a: if?i?in?b: b[i]+=b[i]+1 else: b[i]=1 print?b


小練習

#coding:utf-8 #用戶輸入名字和分數,并保存到list。如果輸入為空,打印并結束循環。并算出平均值 list1=[] count=0 num=0 while?True:x=raw_input('please?input?your?name:')y=raw_input('please?input?your?grade:')if?y.isdigit()?and?x.isalpha():list1.append(int(y))list1.append(str(x))count+=1num=int(num)+int(y)elif?len(x)==0?or?len(y)==0:avg=num/countprint?list1breakelse:print?'input?is?error' print?'平均值是?%s'?%(avg)


轉載于:https://blog.51cto.com/thedream/1812654

總結

以上是生活随笔為你收集整理的python学习 第一篇 基础的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。