python 运算及注释
生活随笔
收集整理的這篇文章主要介紹了
python 运算及注释
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
""" 上面的兩行代碼,在2.0的python中,若想執(zhí)行含有漢字的代碼,是必不可少的,且兩行代碼必寫(xiě)在單個(gè)py文件最上方,之間不可有任何字節(jié)。
且該兩行代碼,可在pycharm,設(shè)置中,直接設(shè)置新建一個(gè)pythan文件時(shí),自動(dòng)添加
+(加) -(減) *(乘) /(除) **(冪,例 1**2,輸出1的2次方)
%(取余,例8%3,輸出8除以3的余數(shù),為2) //(取商,例8//1,輸出8除以1的商,為8)
('''.''')三個(gè)單引號(hào),或(""".""")三個(gè)雙引號(hào),或(#)井號(hào),均是對(duì)同一組標(biāo)識(shí),之間或者它之后的代碼進(jìn)行注釋。此模塊間內(nèi)容不被執(zhí)行
其中注釋還有一種辦法,多行選擇,然后,用“Ctrl+?”。這種方法,同時(shí)注釋多行
break,終止整個(gè)循環(huán);相應(yīng)的"continue,只是終止當(dāng)前一輪循環(huán),繼續(xù)下一輪循環(huán) """
#!/usr/bin/evn python # -*- coding: UTF-8 -*-''' #一:輸出 1 2 3 4 5 6 8 9 10 a = 0 while a <= 10:if a == 7 :passelse:print(a)a = a + 1 print ('...end...') ''' ''' #二:輸出1-100的總和 a=0 b=0 while a<=100:b = a + ba = a + 1 print (b)#三:輸出1-100的奇數(shù) a=1 b=0 while a<=100:b = a % 2if b == 1:print (a)else:passa = a + 1#四:輸出1-100的偶數(shù) a=1 b=0 while a<=100:b = a % 2if b == 0:print (a)else:passa = a + 1#五:求1-2+3-4+5...99的所有數(shù)的和 a=0 #當(dāng)前數(shù) b=0 #之前所有數(shù)的總和 while a<=99:m = a % 2 #判斷當(dāng)前數(shù)字的奇偶if m == 0:b = b - aelse:b = a + ba = a + 1 print (b) '''''' #此模塊是自己寫(xiě)的錯(cuò)誤示例,下方一下示例為正確示例#六:用戶(hù)登錄三次內(nèi)重試##6.1 用戶(hù)登錄三次內(nèi)重試 input('>>>') n=0 while n<3:input ('>>>')if (name== "name",password == "word"): #賬號(hào)密碼正確passn = n + 1else:print ("放棄登錄") '''''' ##6.2 用戶(hù)登錄三次內(nèi)重試 count = 0 while count < 3:user = input('>>>')pwd = input('>>>')if user == 'alex' and pwd == '123':print("歡迎登錄")print("..........")break #此關(guān)鍵字,終止整個(gè)循環(huán)else:print("用戶(hù)名或密碼錯(cuò)誤")count = count + 1 '''
且該兩行代碼,可在pycharm,設(shè)置中,直接設(shè)置新建一個(gè)pythan文件時(shí),自動(dòng)添加
+(加) -(減) *(乘) /(除) **(冪,例 1**2,輸出1的2次方)
%(取余,例8%3,輸出8除以3的余數(shù),為2) //(取商,例8//1,輸出8除以1的商,為8)
('''.''')三個(gè)單引號(hào),或(""".""")三個(gè)雙引號(hào),或(#)井號(hào),均是對(duì)同一組標(biāo)識(shí),之間或者它之后的代碼進(jìn)行注釋。此模塊間內(nèi)容不被執(zhí)行
其中注釋還有一種辦法,多行選擇,然后,用“Ctrl+?”。這種方法,同時(shí)注釋多行
break,終止整個(gè)循環(huán);相應(yīng)的"continue,只是終止當(dāng)前一輪循環(huán),繼續(xù)下一輪循環(huán) """
#!/usr/bin/evn python # -*- coding: UTF-8 -*-''' #一:輸出 1 2 3 4 5 6 8 9 10 a = 0 while a <= 10:if a == 7 :passelse:print(a)a = a + 1 print ('...end...') ''' ''' #二:輸出1-100的總和 a=0 b=0 while a<=100:b = a + ba = a + 1 print (b)#三:輸出1-100的奇數(shù) a=1 b=0 while a<=100:b = a % 2if b == 1:print (a)else:passa = a + 1#四:輸出1-100的偶數(shù) a=1 b=0 while a<=100:b = a % 2if b == 0:print (a)else:passa = a + 1#五:求1-2+3-4+5...99的所有數(shù)的和 a=0 #當(dāng)前數(shù) b=0 #之前所有數(shù)的總和 while a<=99:m = a % 2 #判斷當(dāng)前數(shù)字的奇偶if m == 0:b = b - aelse:b = a + ba = a + 1 print (b) '''''' #此模塊是自己寫(xiě)的錯(cuò)誤示例,下方一下示例為正確示例#六:用戶(hù)登錄三次內(nèi)重試##6.1 用戶(hù)登錄三次內(nèi)重試 input('>>>') n=0 while n<3:input ('>>>')if (name== "name",password == "word"): #賬號(hào)密碼正確passn = n + 1else:print ("放棄登錄") '''''' ##6.2 用戶(hù)登錄三次內(nèi)重試 count = 0 while count < 3:user = input('>>>')pwd = input('>>>')if user == 'alex' and pwd == '123':print("歡迎登錄")print("..........")break #此關(guān)鍵字,終止整個(gè)循環(huán)else:print("用戶(hù)名或密碼錯(cuò)誤")count = count + 1 '''
轉(zhuǎn)載于:https://www.cnblogs.com/baiyuer/p/9548120.html
總結(jié)
以上是生活随笔為你收集整理的python 运算及注释的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Newtonsoft.Json反序列化(
- 下一篇: Python_自定义关键字的使用