zoukankan      html  css  js  c++  java
  • Python笔记 【无序】 【一】

    ----------- r'原始数据'                                                            为了输入【c: d 】

    代码:                                

    输出:                                            

    -----------"""中间格式保持不变
        保持不变
        不变"""

    代码:

    输出:

     -----------num = input("input here")       

          guess = int(num)    输出提示内容,存储的类型是字符串,需要强制转换类型

     代码:此处不是在Shell里,所以需要print(type(xx))  

                                                                在Shell里,tyep(xx)就可以直接输出xx类型

     输出:

    -----------while xx and yy:        and 取代 &&        

        and = &&
        or = ||
        not = !

     代码:

     输出:

     -----------随机数  random模块中的:
        需要首行引入-----import random
        xx = random.randint(1,10)产生1-10的随机数

    代码:

    输出:

    -----------int(xx) float(yy) str(zz) 强制类型转换   注:  int(5.99) = 5      【直接舍去小数部分】

                                                               用str = "xxxx"当作字符串“xxxx“的名字后,无法使用str(yy)的强制类型转换

    代码:

    输出:

     -----------isinstance(a,str) ---判断a是不是str类型,返回true false

    代码:

    输出:

    -----------10 // 8 = 1【//为旧版运算,保留整数】
        10 / 8 = 1.25

    输出:

    -----------** 3**2 = 3^2 = 9
        3**-2 = 3^(-2)
        -3**2 = -(3**2)

    输出:

    ----------- if xx:
        elif yy: 
        else:               【elif == else if】

    代码:

    输出:

    -----------三元操作符:
        n = x if x < y else y
        【如果x<y,n = x,否则y】

    代码:

    输出:6

    -----------assert
        断言,assert xxx
        xxx为假的时候,抛出AssertionError异常,可当作检查点使用

    代码:

    输出:

    -----------for 目标 in 数组名:
             循环体

    代码:

    输出:

    -----------print(x,end='*')---打印x的时候以*结束

    代码:

    输出:

    -----------len(xx)---计算xx的长度

    代码:

    输出:5

    -----------break 直接跳出循环
        continue 终止本轮循环,并跳到下一轮循环

    代码:

    输出:

    -----------range()

    代码:       【生成,5-----> 9-1】

    输出:                                    

    step = d 意义:【生成的是间隔d的等差数列】

     

  • 相关阅读:
    Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
    Codeforces 633H Fibonacci-ish II【线段树】
    一些Fibonacci数列的神奇性质【数学】
    Codeforces 620E New Year Tree【线段树傻逼题】
    Codeforces 828C String Reconstruction【并查集巧妙运用】
    Codeforces 559C Gerald and Giant Chess【组合数学】【DP】
    Codeforces 311B Cats Transport【斜率优化DP】
    BZOJ2933 [Poi1999]地图【区间DP】
    BZOJ3688 折线统计【树状数组优化DP】
    BZOJ2131 免费的馅饼【线段树优化DP】
  • 原文地址:https://www.cnblogs.com/expedition/p/10633307.html
Copyright © 2011-2022 走看看