Python tutorials mobile automated testing interview

Python tutorials mobile automated testing interview

1, super is doing with? In Python2 and Python3 use, what's the difference? Why use super? Please give examples.

answer:

  • A method for super parent class inherits attributes.
  • is the new super class only, so when Python2 used to write in the parameter Object class name in. Python3 default is the new class, do not write directly available.
  • Use super can improve code reusability, maintainability. When modifying code, simply a modification.
  • Code Example:
class baseClass:
 def test1(self, num): print(num) class sonClass(baseClass): def test2(self): super().test1(num) son = sonClass() son.test1(11)

2, read the following code to derive the final result:

def add(n, i): return n+i def test(): for i in range(4): yield i g = test() for n in [1, 10, 5]: g = (add(n, i) for i in g) print(list(g)) # 结果是 [15, 16, 17, 18] 

A: All results are generated expressions, does not call it, is not a value from the inside, it does not work. I enclose my derivation:

n = 1
g = (add(n,i) for i in test()) # print(list(g)) # [1, 2, 3, 4] n = 10 g = (add(n,i) for i in (add(n,i) for i in test())) # print(list(g)) # [20, 21, 22, 23] n = 5 g = (add(n,i) for i in (add(n,i) for i in (add(n,i) for i in test()))) g = (add(n,i) for i in (add(n,i) for i in (5,6,7,8))) g = (add(n,i) for i in (10,11,12,13)) g = (15,16,17,18) print(list(g)) # [15, 16, 17, 18] 

3, fast write front-end HTML, JavaScript, Vue code.

answer:

  • HTML, JavaScript Code:
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="utf-8"> </head> <body> <h1 id="title">xxx公司</h1> <p>xxx公司是一家......</p> <div id="mybox"> <h1>{{a}}</h1> <input type="button" value="按我" v-on:click="add()"> </div> <script type="text/javascript" src="public/bundle.js"></script> </body> </html> <script> var title = document.getElementById("title"); title.onclick = function() { alert('我爱xxx公司,祝我面试成功'); } </script>
  • Vue coding:
import Vue from "vue"; new Vue({ el : "#mybox", data : { a : 100 }, methods : { add : function(){ this.a ++; } } }); 

4, L = [1, 2, 3, 11, 2, 5, 3, 2, 5, 3], obtained with a single line of code [11, 1, 2, 3, 5]

A: list (set (L))

5, L = [1, 2, 3, 4, 5], L [10:] is the result?

A: The empty list (at that time a little nervous, have been "empty list" and "index out of range" wandering between two answers).

6, L = [1, 2, 3, 5, 6], how stars '12356'?

A: Note that this problem personally feel that there is a pit, the elements of the list is not a string, it is not  ''.join(L). Here is how:

s = '' 
for i in L: s = s + str(i) print(s) # 12356 print(type(s)) # <class 'str'> 

7, lists and dictionaries What is the difference?

A: Most lists and tuples are asked what is the difference. Different (1) way to get the element. List obtained by the index value, the dictionary acquisition by key. (2) different data structures and algorithms. The dictionary is hash algorithm, the search speed is particularly fast. (3) occupy different memory.

8, how to end a process?

A: (1) call to terminate method. (2) a method using subProcess Popen module. Simple to use, the specific use, not to proceed here.

9, process, thread, what's the difference? With processes under what circumstances? With thread under what circumstances?

A: (1) the difference between:

  • ① address space and other resources (such as opening a file): between processes independent of each other, shared between threads of the same process. Threads within a process is not visible in the other process.
  • ② Communication: inter-process communication IPC, the threads can read and write directly process data segment (such as global variables) to communicate - need aid process synchronization and mutual exclusion means to ensure data consistency.
  • ③ scheduling and switching: thread context switching is much faster than the process context switch.
  • ④ In a multithreaded operating system, the process is not an executable entity.

(2) usage scenario: simultaneous operation of an object when such operation is a global variable, I use thread, because global variables are shared by all threads.

10. What is ORM? Why use ORM? ORM will not have any effect?

answer:

  • ORM framework may correspond to classes and data tables, can only operate on a data table by classes and objects.
  • By operation of the object class and the corresponding data table, the static class field names and data attribute name correspondence table is not required to write SQL statements.
  • ORM Another effect is generated tables in the database according to the design of the class.

11, to write a piece of code, ping a ip address, and returns a success, failure information.

A: Use subProcess module Popen method (using a simple, specific usage here not to proceed).

12, talk about the interface testing process, tell us about what content request.

A: (1) Process: Get interface documentation, according to the document design interface parameters, get a response, parse the response, calibration results to determine whether the test passed. (2) request content:

  1. 封装了各种请求类型,get、post 等;
  2. 以关键字参数的方式,封装了各种请求参数,params、data、headers、token 等;
  3. 封装了响应内容,status_code、json()、cookies、url 等;
  4. session 会话对象,可以跨请求。

Guess you like

Origin www.cnblogs.com/itye/p/11690214.html