zoukankan      html  css  js  c++  java
  • 第二天学习python的内容

    关于数据类型的方法总结
    print
    ('hello world') num=9/3 print(num) '''若干个运算符的说明 / 除 // 整除 % 取余数 != 不等于 ctrl+? 取注释 ''' # # in 和 Not in 表示在于不在 # name='李宇春' # if '李' in name :#李 为子字符串 # print('ok') # else: # print('error') user='alex' pwd='123' v=user=='alex' and pwd=='123' or 1==2 and pwd=='99854' and 1==2 print(v) # #执行顺序: # 从前往后 # 结果 # true 遇到 or 直接输出true # true and 继续走 # false or 继续走 # false and false # 赋值运算符 count= count+1 count+=1 ''' 1 算数运算符 & 赋值运算符 :结果是值 a=10*10 b=b+1 b+=1 2 比较运算符 逻辑运算符 成员运算符:结果是布尔值 a= 1>6 a= 1>7 or 8>7 b= 'a' in 'afdsaf' ''' # a=123 # #v=a.bit_length() # print(v) # name='nvwu' # v1=name.upper() # print(v1) # py3 数字无论多大 都是 int # bool # list # tuple # dict #str str ''' 1 数字 -int 转换 字符串转换为数字 int(num,base=2/8/16) 转换为二进制 -number.bit_length() 当前数字最少要用多少二进制数字表示 # a='12323' # b= int(a) # print(type(b),b) num='b' a=int(num, base=16) print(a)''' ''' 2 字符串 text='alex' -text.capitalize() 首字母大写 -text.casefold() 全部字母小写 能进行特殊字符的转换 -text.lower() 全部字母小写 只能进行英文的转换 -text.center(20,'中') 空白填充 20代表总长度 中是填充字符 -text.count(e,1,3) 去找字符串中子序列出现的次数 起始和结束位置 -text.encode() -text.decode() -text.endwith('x',1,2) 以xxx结尾 返回true orfalse -text.startwith('x',1,4) -text.find('',0,9) 第一个数字的位数是0 关系是>=0 and <9 找不到返回-1 -text.format 格式化 将字符串中的占位符{}替换为指定的值 text='i am {name}' print(text) i am {name} v =text.format(name='alex')# 也可以不写名字 按顺序自动格式化 从0开始 print(v) i am alex -text.format_map({'name':'lee'}) 对应着传字典 -text.index('s',0,9) 也是寻找的方法和find 一样 区别是找不到时直接报错 '''
  • 相关阅读:
    [leetcode]Set Matrix Zeroes
    [leetcode]Sort Colors
    [leetcode]Combinations
    [leetcode]Subsets
    [leetcode]Search a 2D Matrix
    [leetcode]Best Time to Buy and Sell Stock III
    [leetcode]Best Time to Buy and Sell Stock II
    [leetcode]Best Time to Buy and Sell Stock
    半平面交 (poj 1279(第一道半平面NlogN)完整注释 )
    hdu 4277 USACO ORZ (Dfs)
  • 原文地址:https://www.cnblogs.com/zy0718/p/8428621.html
Copyright © 2011-2022 走看看