Python Full stack exam (i)

Source: Internet
Author: User

1. Two ways to execute Python scripts

You can also use Pycharm

2, briefly describe the relationship between bits and bytes

The data store is in "bytes" (byte), the data transfer is mostly in the "bit" (bit, aka "bit") units, a bit represents a 0 or 1 (that is, binary), every 8 bits (bit, abbreviated to B) to form a byte (byte, abbreviated to B)

3. Brief description of the relationship between ascii, unicode, utf--‐8, GBK

ASCII codes can represent up to 255 symbols

Unicode can only represent a maximum of 65,536 characters

Utf--‐8 is the compression and optimization of Unicode encoding: the contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, the characters in East Asia are saved with 3 bytes ...

GBK is an internal code extension specification for Chinese characters

4. Please write "li jie" the number of digits that are encoded by utf--8 and GBK respectively.

48-bit with Utf-8

32-bit with GBK

5, Pyhton Single-line comments and multiline comments with what?

A single line comment in Python starts with #

A multiline comment in Python uses three single quotation marks ("') or three double quotation marks (" ")

6. What are the considerations for declaring variables?

(1.) variable names can only be any combination of letters, numbers, or underscores

(2.) the first character of a variable name cannot be a number

(3.) The following keywords cannot be declared as variable names

[' and ', ' as ', ' assert ', ' break ', ' class ', ' Continue ', ' def ', ' del ', ' elif ', ' else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' Print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

8. How do I see the address of a variable in memory?

ID (variable Name)

9. What is the purpose of the Automatically generated. PYc file when executing a Python program?

Run python program, pycodeobject compile save file,. pyc file is pycodeobject save file permanently

10.

Write code
A. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login failed!

Name = input ("name:") #输入账号
passwd = input ("passwd:") #输入密码

If name = = "seven" and passwd = = "123": #判断用户名和密码是否相等
Print ("login Successful")

Else
Print ("username or password is not correct, please Re-enter!") ")


Lesson: python break,continue can only be used in a loop like for,while, or it will be an Error.

B. Implement user input user name and password, when the user name is seven and the password is 123, the display login is successful, otherwise the login failed, the failure to allow repeated input three times

For I in range (3):
Name = input ("name:") #输入账号
passwd = input ("passwd:") #输入密码

If name = = "seven" and passwd = = "123": #判断用户名和密码是否相等
Print ("login Successful")

Else
Print ("username or password is not correct, please Re-enter!") ")


C. Implement user input user name and password, when the user name is seven or Alex and the password is 123, the display login is successful, otherwise the login failed, the failure to allow repeated input three times

For I in range (3):
Name = input ("name:") #输入账号
passwd = input ("passwd:") #输入密码

If name = = "seven" or name = = "alex" and passwd = = "123": #判断用户名和密码是否相等
Print ("login Successful")

Else
Print ("username or password is not correct, please Re-enter!") ")

11. Write Code
A. Using a while loop to implement output 2-‐3 + 4‐5 + 6 ... + 100 and

i = 2;
j=0;
While i <= 100:
if (i%2 = = 0):
j = j + i;
Else
j = j-i;
i+=1;
Print (j);

B. Use for loop and range for output 1‐2 + 3‐4 + 5-‐6 ... + 99 and

b = 0
For I in range (1,100):
if i%2 = = 0:
b = B-i
Else
b = b +i
I +=1
Print (b)


C. Using a while loop to implement output 1,2,3,4,5, 7,8,9, 11,12

i=0;
While I<12:
i+=1;
if (i = = 6 or i = = 10):
Print ("\ t", end= " ");
Continue
Print (i, ",", end= "");


D. Using a while loop to implement all the odd numbers within the output 1‐100

I=1
While I <=100:
If (i%2!=0):
Print (i)
I+=1

E. Using a while loop to implement all the even numbers within the output 1‐100

I=1

While I <=100:
If (i%2 ==0):
Print (i)
I+=1


12, the binary representation of the digital 5,10,32,7 is written separately

5:0000 0101 10:0000 1010 32:0010 0000 7:0000 0111


13. Brief description of the relationship between the object and the class (using figurative Methods)

Class is the folder, the object is the folder of the file class has a list, tuples, dictionaries and other elements inside is the object

14, the existing following two variables, please briefly describe what the relationship between N1 and n2?

N1 = 123

N2 = 123

Same as memory address

python内部的优化: -5157之间的赋值变量都是相同的地址,超过这个限制内存地址不同。

15, the existing following two variables, please briefly describe what the relationship between N1 and n2?

N1 = 123456

N2 = 123456

Memory address is not the same

16, the existing following two variables, please briefly describe what the relationship between N1 and n2?

N1 = 123456

N2 = N1

Same as memory address

17, If there is a variable N1 = 5, Use the provided method of int, how many bits can be used to get the variable at least?

Print (int (5). bit_length ()); #3个

18, What are the Boolean values respectively?

True or False 1 or 0

19, Read the code, please write the results of the implementation

A = "alex"
b = A.capitalize ()
Print (a)
Print (b)
Please write out the results: Alex Alex.

20, Write code, There are the following variables, please follow the requirements to achieve each function

Name = "aleX"
A. Remove the space on both sides of the value corresponding to the name variable and enter the content to be removed


Name.strip ()


B. Determine if the value corresponding to the name variable starts with "al" and outputs the result

Print (name.startswith ("al")) #False
C. Determine if the value corresponding to the name variable ends with "X" and outputs the result

Print (name.endswith ("X")) #True
D. Replace "l" in the value corresponding to the name variable with "p", and output the result

Print (name.replace ("l", "p")) # ApeX
e. The value corresponding to the name variable is split according to "l" and outputs the Result.
Print (name.split ("l")) #[' a ', ' EX ']
F. What type of value is obtained after e-segmentation of the previous question?

List
G. Capitalize the value corresponding to the name variable and output the result

Print (name.upper ()) #ALEX
H. Lowercase the value corresponding to the name variable and output the result

Print (name.lower ()) #alex
I. Please output the 2nd character of the value corresponding to the name variable?

Print (name[1]) #a

J. Please output the first 3 characters of the value corresponding to the name variable?

Print (name[0:3])       #al

K. Please output the first 2 characters of the value corresponding to the name variable?

Print (name[-2:])       #eX

L. Please output the value of the name variable corresponding to the index where "e" is located?

Print (name.find ("e")) #3



21. can strings be iterated? if possible, use the For loop for each element?
= "zhangsunan"for i in name: print(i)

22、请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li = [‘alex‘, ‘eric‘, ‘rain‘] 

li2= li[0]+"_"+li[1]+"_"+li[2]


22, write code, such as the following table, as required to achieve each function

Li = [' Alex ', ' Eric ', ' rain ']
A. Calculate the length of the list and output

Print (len (LI))  #3


B. Append the element "seven" to the list and output the added list

Li.append ("seven")
#[' Alex ', ' Eric ', ' Rain ', ' seven '

C. Insert the element "Tony" in the 1th position of the list and output the added list

Li.insert (0, "Tony")
#[' Tony ', ' Alex ', ' Eric ', ' rain '


D. Please modify the element in the 2nd position of the list to "Kelly" and output the modified list


li[1]= "Kelly"
#[' Alex ', ' Kelly ', ' rain '


E. Remove the element "eric" from the list and output the modified list

Li = [' Alex ', ' Eric ', ' rain ']
Li.remove (' Eric ')
Print (li)
#[' Alex ', ' Rain '


F. Delete the 2nd element in the list and output the value of the deleted element and the list after the element is deleted

Print (li.pop (1))
#eric
#[' Alex ', ' Rain '


G. Delete the 3rd element in the list and output the list after the element is deleted

Li.pop (2)
#[' Alex ', ' Eric '


H. Delete the 2nd to 4th element in the list and output the list after the element is deleted

Del li[1:3]
#[' Alex ', ' Nimeide ']


I. Invert all the elements in the list and output the inverted list

Li.reverse () #[' nimeide ', ' Rain ', ' Eric ', ' Alex '


J. Use the index of the for, len, range output list

For I in range (len (li)):    print (i,li[i]); #0 alex#1 eric#2 rain#3 nimeide


K. Use the Enumrate output list element and ordinal (sequence number starting from 100)

For i, J in enumerate (li):    print (i+100, j) #100 alex#101 eric#102 rain#103 nimeide


L. Use the For loop to output all the elements of the list

For I in  range (len (li)):    print (li[i]);


23, write code, such as the following table, please follow the functional requirements to achieve each function
Li = ["hello", ' seven ', ["mon", ["h", "kelly"], ' all '], 123, 446]
A. Please output "Kelly"

Print (li[2][1][1])


B. Please use the index to find the ' all ' element and modify it to "all"

Print (li[2][2].upper ())


24, Write code, There are the following tuple, according to the requirements of the implementation of each function Tu = (' Alex ', ' Eric ', ' rain ')

A. Calculating the tuple length and outputting

Print (len (tu))     #3

B. Gets the 2nd element of a tuple and outputs
Print (tu[1])
C. Get the 第1-2个 element of the tuple and output
Print (tu[0:2])
D. Use the element for the for output tuple
For I in range (len):    print (tu[i])
E. Use the index of the for, len, and range output tuples
For I in range (len):    print (i,tu[i])
F. Use the enumrate output element ancestor elements and ordinal number (ordinal starting from 10)
For i,j in enumerate (tu):    print (i+10,j)


25, there are the following variables, please implement the required function
Tu = ("alex", [one,, {"k1": ' v1 ', "k2": ["age", "name"], "k3": (11,22,33)}, 44])
A. Describing the characteristics of Ganso
Not modifiable, so it's called an immutable List.
B. Can you tell me if the first element in the Tu variable, "alex", could be modified?
Cannot be modified
C. What is the value of the "k2" in the Tu variable? can it be modified? if so, add an element "Seven" to it.
Can be modified, is the list
tu[1][2]["k1"] = "seven"
D. What is the value of "k3" in the Tu variable? can it be modified? if so, add an element "Seven" to it.
Tu[1][2]["k3"]=list (tu[1][2]["k3"]) tu[1][2]["k3"].append ("Seven") tu[1][2]["k3"]=tuple (tu[1][2]["k3"]) Print (tu)

26. Dictionary dic = {' K1 ': "v1", "k2": "v2", "k3": [11,22,33]}
A. Please loop out all the keys
For i in Dic.keys ():    print (i)
B. Please loop out all the value
For i in Dic.values ():    print (i)
C. Please loop out all the keys and value
For i,j in Dic.items ():    print (i,j)
D. Add a Key-value pair in the dictionary, "k4": "v4", and output the added dictionary
dic["k4"] = "v4" #{' K1 ': ' v1 ', ' K2 ': ' v2 ', ' K3 ': [one, one, one], ' K4 ': ' v4 '}
E. In the modified dictionary, the value of "k1" corresponds to "alex", output the modified dictionary
dic["k1"] = "alex" #{' K1 ': ' Alex ', ' K3 ': [one, one, one], ' K2 ': ' v2 '}
F. Please append an element 44 to the value of the k3, and output the modified dictionary
Dic["k3"].append (44)
#{' K1 ': ' v1 ', ' K3 ': [one, one, one, one], ' K2 ': ' v2 '}
G. Insert element 18 in the 1th position of the K3 corresponding value, output the modified dictionary
Dic["k3"].insert (0,18) #{' K3 ': [' + ', ' one, ', '], ' K1 ': ' v1 ', ' K2 ': ' v2 '}
27. Conversion
A. Converting a string s = "alex" to a list
Print (list (S))
B. Convert the string s = "alex" to Cheng Yuanju
Print (tuple (S))
C. Convert the list li = ["alex", "seven"] to the Narimoto group
Print (tuple (LI))
D. Convert the progenitor tu = (' Alex ', ' seven ') to a list
Print (list (tu))
E. Convert the list li = ["alex", "seven"] to a dictionary and the dictionary key is incremented by 10
Li2 = [10,11]print (dict (zip (li2,li)))

28. transcoding

n = "old boy"

A. Convert the string to UTF-8 encoded byte and output, then convert the byte to Utf-8 encoded string, and then output

Sstr=n.encode ("UTF-8") sstr.decode ("UTF-8") Print (sstr)
B. Convert the string to GBK encoded byte and output, then convert the byte to GBK encoded string, and then output
Sstr=n.encode ("GBK") Print (sstr.decode ("GBK"))






 

Python Full stack exam (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.