编程语言
首页 > 编程语言> > python 3 条件判断

python 3 条件判断

作者:互联网

条件判断:

if 语句

if else 语句

 

 




 

 

 

循环:

 

 

 range(5)是生成小于5的0,1,2,3,4,如果加上一个list[range(5)] 就是生成一个列表[0,1,2,3,4]
如果计算0-100的整数的相加和:  
sum = 0  
for i in range(101):
    sum = sum+i
  print(sum)

第二种是while循环,只要条件满足就一直循环,条件不满足退出循环。

(这里计算100以内的所有奇数的和)
sum = 0
n = 99
while n > 0:
  sum = sum+n
  n = n-2
print(sum)

TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back

标签:判断,TRANSLATE,python,sum,range,循环,location,条件,document
来源: https://www.cnblogs.com/frank1/p/16617690.html