Home>Article>Backend Development> What are the basic knowledge of python
Basic knowledge of Python: 1. References and objects; 2. Mutable data types and immutable data types; 3. Reference passing and value passing; 4. Deep copy and shallow copy; 5. Basic data types; 6. Keywords, identifiers and built-in functions; 7. Arithmetic, assignment operators, etc.
Related learning recommendations:python tutorial
Basic knowledge of Python:
1. Two ways to execute a script
Python a.py Directly call the Python interpreter to execute the file
chomd x a.py ./a.py #Modify the attributes of the a.py file to be executable, and use ./ to execute a.py File
2. Briefly describe the relationship between bits and bytes
##1bytes=8bit, 2**8=256, OK Represents the changes in 256,
ascii is the earliest standard information interchange code used in the United States. It represents all uppercase and lowercase letters and various symbols in binary. There are 256 in total, with some Latin and other characters added. 1byte represents one character,
Unicode is to unify the different languages of the world. It uses 2 bytes to represent a character, which can express 2**16=65556. It is called a universal language. Features: fast, but a waste of space,
can be used in memory processing, compatible with utf-8, gbk, ASCII,
utf-8 In order to change this shortcoming of Unicode, It is stipulated that 1 English character is represented by 1 byte, and 1 Chinese character is represented by 3 bytes. Characteristics: saving space and slow speed. It is used in hard disk data transmission and network data transmission. Compared with hard disk and network speed, the performance is inferior. What comes out,
gbk is the Chinese character encoding, using 2 bytes to represent a character,
gbk is 2bytes=16bit
5. What are the uses for single-line comments and multi-line comments in Pyhton?
#Multi-line comments """ """Three double quotes or three single quotes put the content to be explained in the middle, ''' '''
6. What are the precautions for declaring variables?
cannot be named after Python keywords,
can indicate the meaning of the variable
8. How to check the address of a variable in memory?
z=9. When executing a Python program, automatically What is the function of the generated .pyc file?
10. Write code
name=
while循环: count=
for count in range(3) : name = input('name:').strip() pwd = input('pwd:').strip()if name=='seven' and pwd=='123' :print('ok')else:print('error') count += 1
while 循环 count =
for count in range(3) : name = input('name: ') pwd = input('pwd: ')if name == 'seven' and pwd == '123' or name == 'alex' and pwd == '123':print('ok')else :print('error') count+=1
count=
num=0count=1for count in range(100) :if count % 2 == 0 : num=num - countelse : num=num+countprint(num)
count=
for i in range(101) :if i %2 != 0 :print(i)
count=
for i in range(100) :if i %2 == 0:print(i)
count=
print(
print(
n1,n2是连个不同的变量名,但值都一样,都指向了同一个内存地址,
n1=5
print(int.bit_length(n1)) 结果 3
False .Ture ,或1 和0
print(name.strip())
print(name.startswith(
print(name.endswith(
print(name.replace(
print(name.split(
print(name.upper()) print(name.lower())
print(name[1
print(name[:3])
print(name.index(
依赖索引 name =
for i in name:print(i)
print(
li = [
li.append(
['alex', 'eric', 'rain', 'seven']
li.insert(
li[
li = [ ['alex', 'rain'] 指名道姓的删除
li = [
li = [ eric ['alex', 'rain']
li = [ 'alex', 'eric', 'rain'] del li[ 1:] print(li)
li = [
li = [
li[
tu = (
print(tu[
for i in range(len(tu)) :print(tu.index(tu[i]))
10 alex 11 eric 12 rain
for k in enumerate(tu,10) :print(k)(10, 'alex')(11, 'eric')(12, 'rain')25、有如下变量,请实现要求的功能tu = ("alex", [11, 22, {"k1": 'v1', "k2": ["age", "name"], "k3": (11,22,33)}, 44])
元组,不可以
列表,可以 tu = (
for i in dic:print(i)
for i in dic:print(dic[i])
for i in dic: print(i,dic[i])
dic[
dic[
dic[
dic[
s =
s =
li = [
tu = (
d. 将列表 li = ["alex", "seven"] 转换成字典且字典的 key 按照 10 开始向后递增dic={}for k,v in enumerate(li,10) :----li要放在前面,序号放在后面dic[k]=vprint(dic)
n = " 老男孩 " a=n.encode( 'utf-8') print(a) b=a.decode( 'utf-8') print(b)
a=n.encode(
count=
count=
li=[
The above is the detailed content of What are the basic knowledge of python. For more information, please follow other related articles on the PHP Chinese website!