day07 learning Summary

Exception Handling

I.e. exception handling (error, Error)

  1. Early prevention
    condition if an error occurs is predictable, we need to deal with if: prevention before the error occurred
AGE = 10
while True:   # 规定下面的if为true时,条件满足
        age = input('>>:').strip() 
        if age.isdigit():   # 只有在age为字符串形式的整数时,下列代码才不会出错,该条件是可预知的 
                age = int(age)
                if age == AGE:
                        print('you got it')
                        break
  1. After the prevention of
    the condition if an error occurs is unpredictable, you need to use try ... except: processing after an error
'''
try:     
    代码块
except # 异常类型:     
    执行条件:try中一旦检测到异常,就执行这个位置的逻辑
'''

'''
try:  # 尝试
     print(1 / 1)  # 有错误就跳过,没有错误就执行
except ZeroDivisionError:  # 错误被跳过了(捕捉了)
     pass  # 啥也不做
'''

try:
    key = input('输入一个key获取字典中的值')
    dic = {'a': 1}
    q = dic[key]  # KeyError
    print(q)
except Exception as e: # Exception万能异常 # 把错误信息输入出来,同时一般把该错误记录到日志中
    #logging.info(e)  -> 程序员看(记录日志)
    print('你输入有问题') #   -》 用户看

leetcode

Two numbers and

  1. Replace the interpreter, change the background color

  2. Analysis of the subject (demand)

  3. 20-40 minutes, if you really want out - "Do not Sike -" go to the comments section to see others loaded to force (Solutions) --- You are currently not think because your first contact, questions 10-15 after not look at the answer. Can Sike

  4. Paper strokes

String built-in method

Built-in method: built-in method (arranged in advance, will be used on the line)
built-in method string: string to use only, the list can not be used

  1. Index values
print(s[0])
  1. slice
print(s[0:4])
  1. Member operator
print('nick' in s)
print('nick1' in s)
  1. loop for
    s = 'nick handsome'
for i in s:  # n i c k  h a
    print(i)
  1. Only ()
print(len(s))

The next telling the string out of the way

  1. strip (): remove the default ends spaces,
s = '****  ni  ck  '
print(s)

print(s.strip())  # 去空格
print(s.strip('*'))  # 去*
print(s.strip('n* '))  # 去 和*和n

7.lstrip () / rstrip (): the left / right edge

s = '**nick**'
print(s.lstrip('*'))
print(s.rstrip('*'))

8.startswith () / endswith (): to. . Beginning / to. . end

s = 'nick'
print(s.startswith('nick'))
print(s.endswith('k'))

9.find () / index (): Get the index position of a particular element

s = 'nick'
print(s.find('a'))  # 找不到返回-1
# print(s.index('a'))  # 找不到报错

10.join (): the list of elements within the splice out

print('*'.join(['a', 'b', 'c']))

11.split (): Cutting

s = 'a*b*c'
print(s.split('*'))  # 以*为切割符号,切割字符串

12.center/ljust/rjust: print more beautiful, center / Left / right of abode

print(s.center(50, '-'))
print(s.ljust(50, '-'))
print(s.rjust(50, '-'))

13.isdigit()/isalpha()

s = 'a'
print(s.isdigit())  # 是否为纯数字
print(s.isalpha())  # 是否为纯字母

14.count (): Count

s = 'nick nick'
print(s.count('nick'))

The basic use of selenium

  1. What is selenium?
    It is an automated testing tool.

  2. Why use selenium?

    Advantages: it can be driven by the browser, to bypass the login authentication slide

    Disadvantages: low efficiency reptiles

  3. How to use selenium?

  • Install the driver: http://npm.taobao.org/mirrors/chromedriver/2.38/

  • Installation request library: pip install selenium

  • html tag lookup:

    • Find by property
    • Priority use (mainly with two front)
      • id: value is unique
      • class: there may be a plurality of values
      • name: worth only attribute input which has
  • element: a first look
  • elements: Find all

Guess you like

Origin www.cnblogs.com/bowendown/p/11431394.html