zoukankan      html  css  js  c++  java
  • 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。初次发博客有错误或是哪里写的不好,请多多指教。

  • 相关阅读:
    突破ASLR之理论篇
    安装cocoaPods
    iOS 文字渐变
    iOS_科大讯飞快速实现语音搜索功能Demo
    Button宽度自定义
    全局手势按钮(随意拖动,点击事件)
    文字广告轮播这个就够用了
    一些有趣的三方开源库
    SVN的简单使用和积累
    如何在手机上面安装iPA应用包
  • 原文地址:https://www.cnblogs.com/fromzore/p/7772242.html
Copyright © 2011-2022 走看看