zoukankan      html  css  js  c++  java
  • day01 python入门

    一:Python3.x和Python2.x的区别

    1. Py3.X源码文件默认使用utf-8编码
    2. 去除了<>,全部改用!= 
    3. 整型除法返回浮点数,要得到整型结果,请使用// 
    4. 去除print语句,加入print()函数实现相同的功能
    5. 新的字符串格式化方法format取代%
    6. 3.x某些模块进行改名 _改为. 大多数改成小写。
    7. 3.x raw_input改成input
    #具体参考:http://www.cnblogs.com/codingmylife/archive/2010/06/06/1752807.html

    二:Hello World程序

    print("Hello World!")

    三:声明变量及变量名定义规则

    示例:
      test = 123
    变量定义规则:
      下划线或字母)+(任意数目的字母、数字或下划线
      变量名必须以下划线或字母开头,而后面接任意数目的字母、数字或下划线
      不能以数字及特殊字符开头

    四: 用户输入

    示例:
        name = input("What is your name?")  # 将用户输入的内容赋值给 name 变量
        print("Hello " + name )    # 打印输入的内容

    五: Python注释

    单行注释:
      井号(#)常被用作单行注释符号,在代码中使用#时,它右边的任何数据都会被忽略,当做是注释。
      print 1 #输出1
     #号右边的内容在执行的时候是不会被输出的。
    多行注释:
      多行注释是用三引号'''   '''包含
       '''
       this is note
       这里是注释
       '''

    六: Python数据类型

    1、字符串
        用引号括起来表示字符串,例如:
        str='this is string';
        print str;
    2、布尔类型
        True False
    3、整数
        int=20;
    4、浮点数
        float=2.3;(既小数)
    5、列表
        使用[ ]括起来,例如:
        nums=[1, 3, 5, 7, 8, 13, 20];
    6、元组
        使用( )括起来,例如:
        nums=(1, 3, 5, 7, 8, 13, 20);
    7、字典
        使用{key:value}括起来,例如:
        nums={1:a,2:b}

    七:python条件判断

    num = 10
    if num == 10:
        print('yes')
    elif num < 10:
        print('small')
    else:
        print('large')

    八:Python循环

    #-----------for循环--------
    for i in range(10):
        print(i)
    #---------while循环--------
    while True:
        print('good')
        break    #使用break可终止循环
                     #使用continue可终止本次循环
  • 相关阅读:
    Luogu P3346 [ZJOI2015]诸神眷顾的幻想乡
    SP10570 LONGCS
    Luogu P3975 [TJOI2015]弦论
    hihocoder #1457 : 后缀自动机四&#183;重复旋律7
    Luogu SP8222 NSUBSTR
    SP7258 SUBLEX
    Luogu P4070 [SDOI2016]生成魔咒
    [清华集训2016]组合数问题
    [NOIP2018TG]保卫王国
    [note]克鲁斯卡尔重构树
  • 原文地址:https://www.cnblogs.com/xuanouba/p/5491745.html
Copyright © 2011-2022 走看看