Python学习Day3

一、与用户交互:在Python2中的raw_input与Python3中的input是一样的。

                input()是接受用户的输入,并把用户的输入的内容转成字符串。

二、格式化输出

     需要用到占位符:%s、%d

    print(‘my name is %s,my age is %s’ %('lgh',22))

三、数据类型

     int 整型

     float  浮点型

     字符串

     列表

     字典

四、运算符

     1.算数运算符

        +、-、*、/

        10/3————>保留小数部分

      10//3————>保留整数部分

         10%3—————>取余数

         2**3——————>2的3次方

     2.逻辑运算符

  and  or not

        and:只有当所有条件都为True,最后结果才为True。

     or:任意一个条件为True,最后结果为True.

        not:最后结果取反。

     3.比较运算符

  !=  不等于     

  ==  等于指数值

     4.身份运算符

  is  比较的是id

      5.赋值运算符

  =

    +=

       -=

  %=

五、流程控制if......else

  age=20

  if age<26:

    print('姐姐好')

  else:

    print('阿姨好')

六、流程控制while

      为了重复使用一段代码的功能,但却不用重复写一段代码,就要用到while循环功能。

       

    while 条件:
        pass

    while True:
        pass



    while True:
        name=input('>>:')


    while+break:跳出本层循环
    while+continue:跳过本次循环,进行下一次循环


    count=0
    while True:
        if count == 3:
            break
            count+=1
        print('=======>')
        count+=1
        continue
原文地址:https://www.cnblogs.com/Liu-guang-hui/p/9343453.html