7.29 notes quiz

Python implementation of the program in two ways

Interactive (eg: jupyter)

Pros: Run an implementation of a

Disadvantages: Close disappear

Command-line (eg: pycharm)

Pros: has been saved

Disadvantages: all finished before they can debug bug

Although txt file can run, but try to use py file

Later try to use pycharm or jupyter

Code farmers (only grammar, without thinking (hands-on experience / own summary), project experience (summary bug))
each encounter a bug, recorded (is not it a look)

What are the variables: Description of changes in the state of things in the world

Height: 160, weight: 140

"""
height = 160
print(height) # 160(变量值)
"""

weight = 140

print (weight) # 140 (variable value)

weight = weight + 1

print(weight) # 141

Compositional variables

Variable name (variable value received) = (assignment symbol) variable value (value) is defined variable #

Naming the variable name

Height = 180 # is not recommended, but may do so

print (height)

weight = 160

name = 'nick'

1. Variable names must consist of number / letter / underscore _ Composition

height_of_nick = 180 # underlined only when connected with

2. Variable names are readable (sense) deposit is not an end, is the purpose of taking

3. Do not use keywords as variable names (characters that have a special meaning)

'''
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
'raise', 'return', 'try', 'while', 'with', 'yield']
'''

Both definitions way a variable name

height_of_nick = 180 # underlined formula (convention)
Print (height_of_nick)

Heightofnick = 180 # hump body (very low, such as (C / the JAVA))
Print (heightofnick)

Constant: the same amount, nature is a constant variable, but the variable name in all capital convention constants, not to change the constants

age = 18 #变量
Age = Age Tasu 1
Print (Age)

AGE = 18 # So all uppercase letters is constant

AGE = AGE + 1
print(AGE)

Variable memory management (frequently asked interview)

##: description of the state of all things worldly
height = 180 # define a variable
print (180) # print will automatically help you create a variable 180, later printed, immediately release the memory space 180

The reference count is defined

# Define a variable, the memory will open up a memory space to store the variable
# reference count (for variable value)
# reference count is 0, touch
# send garbage collection mechanism, release the memory occupied

The definition of small integers pool

Since the [#] -5,256 used more, [- 5,256] is automatically opened when the python interpreter to start, so they are not affected by garbage collection mechanism for jupyter
### Note: pycharm in optimized , a short interval of time, no matter how big, id are the same

GIL Global Interpreter Lock

Three variables defined characteristic values

height = 180 # variable name (descriptive)
# fetch values of the memory address for the value of the variable
Print (ID (height))
# data types, variable values for
print (type (height)) # int type (integer type)

= name 'Nick'
Print (type (name)) # STR type (string string)

Fancy assignment

height_of_nick = 180

height_of_handsome = 160

heigh_of_yongjiu = 170

print(height_of_nick)

print(height_of_handsome)

print (heigh_of_yongjiu)

Cross assignment (decompression)

height_of_nick,height_of_handsome,heigh_of_yongjiu=180,160,170
print(height_of_nick)
print(height_of_handsome)
print(heigh_of_yongjiu)

Modify the x and y at the same address how to ensure cases

x = 2000
print ( 'x:' id (x))
y = 1000
print ( 'y:' id (y))

Thinking of intermediate variables

# z = x
# x = y
# y = z

Cross assignment

X, Y = Y, X
Print ( 'Y:', ID (Y)) # same memory address, the same value must
print ( 'x', id ( x))

x = 1000

y = 2000

print ( 'y', id ( y)) # same value, the memory address is not the same
print ( 'x', id ( x))

Chain assignment (the same value to use)

# # a = 10
# b = 10
# c = 10
# print(a,b,c)

a=b=c=10
print(a,b,c)

Note

# Single-line comments

# Interpretation; let code to run when the python interpreter not to be interpreted, that let him senseless

# a = 10
# print(a)

Picasso picasso_height = 160 # height, interpreted code means

# Explained above code into code block

Print # 0-9

for i in range(10):

print(i)

# Ctrl + / (comment shortcuts)

Multi-line comments #
'' '
A = 10
Print (A)
' ''

Do not ask the purpose of the copy, the program had an epiphany in your knock code, never epiphany when you think

Guess you like

Origin www.cnblogs.com/chmily/p/11266020.html