zoukankan      html  css  js  c++  java
  • 9-Python基础知识-day1

    Python基础知识-day1

    Python 2 和Python 3 的区别:

          Python2 源码不标准,混乱,重复代码多;#-*-encoding:utf8 -*- 解决python2显示中文的问题

          Python3 统一标准,去除重复代码;

    Python 的环境

    编译型:一次性将全部代码编译成二进制文件; C C++

        优点:运行效率高;

        缺点:开发速度慢,不能跨平台; 

    解释型:当程序运行是,从上至下一行一行的解释成二进制;python php

        优点:开发效率高,可以跨平台;

        缺点:运行速度慢; 

    变量

    变量由数字、字母、下划线任意组合,且不能以数字开头;

      具有描述性;

      不能用Python中的关键字;

      不能用中文和拼音;

    常量

    常量是一直不变的量;全部用大写字母组成,不可更改;

    注释

      单行注释用#

      多行注释用三个单引号或者双引号

    用户交互input

      数据类型全部为str

    基础数据类型

      bool:True false

      数字:int  + - *  /  %  //

      字符串:str 加引号的视为字符串 ,可相加,可以与数字相乘;

    if语句

    第一种

      if 条件:

        结果

    第二种

      if 条件:

        结果

      else:

    第三种

      if 条件:

        结果

      elif 条件:

        结果

    第四种

      if 条件:

        if 条件:结果

    while循环语句

    while 条件:

      结果

    终止while循环:

    1、改变条件

    2、 break 强制终止循环

    3、continue 结束本次循环,继续下一次循环

      

    1、 求1-100的所有数的和  

    count = 1
    sum = 0
    while count<=100:
        sum = sum +count
        count +=1
    print(sum)

     2、使用while循环输入 1 2 3 4 5 6     8 9 10  

    count =0
    while count<10:
            count +=1
            if count ==7:
                 pass
            else:
                 print(count)

    3、输出 1-100 内的所有奇数  

    count =0
    while count<=100:
            count +=1
            if count % 2 != 0:
                 print(count)
         

    4、输出 1-100 内的所有偶数  
    count =0
    while count<=100:
            count +=1
            if count % 2 == 0:
                 print(count)

    5、求1-2+3-4+5 ... 99的所有数的和  

    count =0
    sum = 0
    while count<=100:
            count+=1
            if count % 2 == 0:
                 sum = sum - count
            else:
                sum = sum + count
    print(sum)

    6、用户登陆(三次机会重试)

    
    
    nam = "tim"
    Pwd="cisco"
    n = 1
    while n<=3:
        name = input("Please Your name: ")
        password = input("Please Your Password: ")
        if n==3:break
        elif name==nam and password==Pwd:
            print("Your password is good !")
            break
        else:
            print("Your Password is wrong !")
            n+=1
  • 相关阅读:
    数组乘积更新
    win向linux传文件
    遇到autoreconf: not found
    python thread
    aptitude
    virtualbox安装ubuntu出现“The system is running in low-graphics mode”
    webform用户控件
    LinQ to SQL
    表单验证
    文件上传
  • 原文地址:https://www.cnblogs.com/zhangtengccie/p/9902536.html
Copyright © 2011-2022 走看看