• Python学习第一周


    • 一、我的第一个程序
    print("Hello word!")

      所以说python是一款非常简洁的语言,不像c,c++等等写一个简单的小程序还要调用一堆库。另外,python 3的版本支持中文编写。

    • 二、变量 的使用

              Python是一种动态的,强类型语言

    name="fromzore"
    print(name)

    不用定义变量的类型,系统根据你输入的自动给变量定义

    name="fromzore"
    age=input("age");
    pt2="%s你的年龄是%s"%(name,age)
    print(pt2)

    因为在input中,他默认你传入的是str类型,所以想用%d就需要强制转换

    name="fromzore"
    age=int(input("age"))
    pt2="%s你的年龄是%d"%(name,age)
    print(pt2)

    无报错。

    • 三、循环

    循环分为while循环和for循环,和c等语言的不同之处在于python的这些循环可以后接else语句

    age=18
    sum=0
    while sum<3:
       count= int(input("age"))
       sum+=1
       if sum==count:
           print("you are right")
           break
       elif age<count:
           print("It is biger than age")
       elif age>count:
           print("It is smaller than age")
    else:
        print("Multiple input errors")

    结果是这样的

    for循环

    for i in range(3):
       count= int(input("age"))
       sum+=1
       if sum==count:
           print("you are right")
           break
       elif age<count:
           print("It is biger than age")
       elif age>count:
           print("It is smaller than age")
    else:
        print("Multiple input errors")

    将while改为for结果是一样的。

    ps:所用python版本为python 3。初次发博客有错误或是哪里写的不好,请多多指教。

  • 相关阅读:
    Nginx配置简单说明
    JVM需要知道的一些设置参数
    Maven仓库(私服)中上传第三方jar包
    maven本地资源库设置
    sweetalert2使用教程
    《算法导论》学习笔记——二叉搜索树
    散列表
    跨域请求
    mvn常用命令
    Springmvc配置笔记
  • 原文地址:https://www.cnblogs.com/fromzore/p/7772242.html
Copyright © 2020-2023  润新知