zoukankan      html  css  js  c++  java
  • python的基本用法(一)

    1.什么变量,什么是数据类型?

    变量就是用来存放东西的,

    数据类型:字符串str,整数int,浮点数(小数)float

    type()函数用来检验数据格式的类型

    2.什么是for循环,什么是while循环?

    for  变量  in range(数量)循环次数控制,不需要计数器

    for count in range(7):

       count=count+1

       guess=input('请输入你猜的数字:')

       guess=int(guess)

       if guess >num:

        print('你猜大了')

       elif guess<num:

         print('你猜小了')

      else:

        print('恭喜你猜对了')

        break

    else:#正常结束循环之后,执行else里的语句

       print("今天次数已用完")

    while 循环 需要计数器count

    while  count<n:

      count=count+1

      a=input('请输入:')

      a=int(a)

      if   条件语句:

        print('结果1')

        continue

      elif 条件语句:

        print('结果2')

                   continue

    else:

      print('结果3')

    #break 在循环里面只要遇到break就立即结束循环

    #contiue 在循环里面遇到continue,结束本次循环,进行下一次循环

    3.什么是字符格式转换?

    import datetime

    username=input('请输入你的名字:')

    today=datetime.datetime.today()

    word='欢迎'+username+'登录!'+'今天的日期是'

    word2='欢迎 %s 登录!今天的日期是:%s'%(username,today)

    word3='你的年龄是%d 你的分数是%.2f'%(18,92.5)

    print(word2) print(word3)

    #%s字符串str,%02d整数(01,02,03),%.2f小数(0.01),%r:会重现所表达的对象

    4.什么是print函数,什么是input?

    print用来打印输出东西:例如:print(''hello,world!'),控制台就会输出:hello,world!

    input用来输入东西,input接收的全是字符串

  • 相关阅读:
    codeforces 719A:Vitya in the Countryside
    POJ3233 Matrix Power Series
    codevs1409 拦截导弹2
    BZOJ1562 [NOI2009]变换序列
    POJ1325 Machine Schedule
    codeforces 715B:Complete The Graph
    BZOJ1972:[SDOI2010]猪国杀
    浅谈模拟
    BZOJ2548:[CTSC2002]灭鼠行动
    BZOJ1033:[ZJOI2008]杀蚂蚁
  • 原文地址:https://www.cnblogs.com/yulinlincoding/p/9960681.html
Copyright © 2011-2022 走看看