码迷,mamicode.com
首页 > 编程语言 > 详细

Python的基本语句

时间:2018-08-06 12:19:48      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:用法   补充   使用   count   方法   python   tab键   bsp   pytho   

if条件语句

 (1)if 条件的判断 :  (冒号)

 if 1==1 :

    print (‘真的啥也不会‘)

else:

    print (‘以后就会了‘)

### 代码块的介绍:在同一列下的为代码块,如上,if下的print就是一个代码块。

###一般为空4格为标识,或直接按TAB键。

 

(2)if的嵌套:

if n==1 :

  print(‘哈哈‘)

  if n==2 :

    print(‘呵呵‘)

  else:

    print(‘hehe‘)

else:

  print(‘haha‘)

##注意代码块。。。。。

 

(3)if elif 的用法:

if n==1 :

  print (‘你好‘)

elif n==2 :

  print (‘年后‘)

elif n==3:

  print (‘真香‘)

else:

  print (‘sb‘)

 

  如果想要直接else 则要:

if n==1 :

  pass      关键字 :不执行当前 直接跳过。

else :

  print(‘sb‘)

 

while的使用方法:

(1)while count ==1:

  print("哈哈")

使用时同样需要注意代码块。

(2)while else 的使用 

while count <10:

  print("haha")

       count =count +1

else:

  print("hehe")
使用时同样注意代码块

(3)continue break

while count<10:

  if count==7:

    count=count+1

    print(‘haha‘)

    continue

  else:  

    print(‘haha‘)

    count=count+1

其中 ,continue的用法就是当满足if时,遇到continue后返回if,继续执行。 即当=7时,continue后到else输出haha

 

break时, break的作用是跳出所有循环.

 

对前面的补充:

(1)当现实字符串时 只能是"" ‘‘ """ """ 这几种方式

 

 

 

  

 

Python的基本语句

标签:用法   补充   使用   count   方法   python   tab键   bsp   pytho   

原文地址:https://www.cnblogs.com/SmileXiaoxiao/p/9415322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!