Day03.Practice

# Today exercise

1. The following code references for the 10 count of how many?

`` Python `
# example 1
the X-10 =
the y-10 =
z = 10
del del is the y-# delete the current variable binding relationship with the value of
` ``

2. Description of Python small integer pool concept

1  small integer pool: Python implementation int time there is a small integer pool.
2  in order to avoid creating the same value is repeated application efficiency caused by the memory space,
 . 3 the Python interpreter created when the starting pool small integer range [-5,256 ],
 4 Small Integer object is within the range to be reused within the scope of the global interpreter will never be GC (Garbage Collection) recovered

3. The values ​​of the following variables is determined, the same memory address

```python
x = 257
y = x
z = 257
```

. 1  ID is the same as ① X and y
 2  ② and z are the same on X:
 . 3  line interactive commands are not identical, the Python editor
 4 because the editor application pool space greater than an integer of interpreter

Data type role talked about today python 4. brief definition of the way, note

① defined manner: 
'Data Type ()' can be defined in the form of, for example, test = int (3) 
or directly the data type name is omitted, directly to a writing characteristic data itself automatically identify, for example, test = 'This is a test . ' 
① int 
role: to record an integer, such as age, number, etc. 
Note: Python 2 has long integer, long integer not Python3 
② float 
effect: decimal to record, such as weight, wages 
③ str 
Definition: single or double quotation marks or triple 
role: to record string 
Note: three reference is given to the needs of the string has a reference 
string can be added multiplication; adding a new application memory space in memory, values in order to write, want to take this value is repeated n times to write 
④ list 
definition: in brackets, separated by commas, the value written to any data type 
action: recording a plurality of values used to facilitate removal value anywhere 
Note: IT industry generally scratch count 
⑤ dict 
defined: braces, by the key: value pairs in the form of a plurality of data records recording 
function: a plurality of data recording, a value convenient Characterized access data 
Note: value when a reference key with the key brackets 
⑥ Boolean 
defined: only two values True and False 
to indicate the judgment result: the role 
NOTE: the first letter in uppercase boolean Python

 5. formatted output to achieve the following output

```python
#############info of jason#############
name:jason
age:18
weight:75
height:183
IQ:250
##################end##################
```

name = input('your name:')
age = input('your age:')
weight = input('your weight:')
height = input('your height:')
IQ = input('your IQ:')
msg='''
#############info of %s#############
name:%s
age:%s
weight:%s
height:%s
IQ:%s
##################end##################
'''
print(msg%(name,name,age,weight,height,IQ))

  

6. Try to use the dictionary as much detail shown in your hometown and other cities and counties

= {addr 
	'Henan': 
		{ 'MAGAZINE': 
			{ 'Xinmi': 
				{ 'laiji': 
			} 
		} 
	} 
}

  


7. The line of code that implements the following code to achieve the desired functionality

```python
x = 10
y = 10
z = 10
```

x = y = z = 10

  

Embodiment 8. Two exchange x and y values ​​of

```python
x = 666
y = 888
```

x, y = y, x
 print (x, y)
method one
temp = x
x = y
y=temp
print(x,y)
Second way

 

9. elaborate decompression assignment principles and precautions

The value of a single list out and binds to a new variable name
principle
a. Number decompression using variable names and the number of elements in the list must be equal 
b. can extract all sequentially removed can not be removed separately 
c. convention may be ' _ ' values do not want to use decompression unbinding
note
= example [1,2,3,4 ] 
e1, e2, e3, e4 = example
 print (e1, e2, e3, e4) 

example = [1,2,3,, 4 ] 
e1, _, _, e4 = example # 等同于e1, * _, e4 = example 
print (e1, e2, e3, e4)
Examples

 

Guess you like

Origin www.cnblogs.com/buzaiyicheng/p/11116153.html
Recommended