days03

1. Briefly two ways to execute Python programs as well as their advantages and disadvantages:

Interactive

Input line, explained his party

Interactive, without the use of print, will automatically print, generally do debug ()

Disadvantages: Turn off the program is gone

Command line

Interpretation of a text

python is an interpreter

python file path

Disadvantages: cumbersome debugging

2. Description of Python garbage collection:

Garbage collection mechanism: When the value of a variable reference count is 0, it will trigger a garbage collection mechanism, the magnitude of change will be recycled

3. For the following codes:

x = 10
y = 10
z = 10
del y

10 reference count of how many? 3

x = 257
y = x
del x
z = 257

corresponding to the variable x 257 reference count of how many? 2

4. DESCRIPTION Python small integer pool concept:

# 小整数池
age1 = age
print(id(age1))

# 当python启动的时候,会自动定义[-5,256]之间的整数变量,他们的内存空间已经写死了

5. For x = 10, please use the Python code print variable values, respectively, the memory address of the variable value and the variable data types:

x = 10

# 打印值
print(x) # 10

# 打印内存地址
print(id(x)) # 1560309504

# 打印数据类型()
print(type(x)) # <class 'int'>

6. For the following codes:

x = 257
y = x
z = 257

#请判断x、y、z的变量值是否相同?x、y、z的所在的内存地址是否相同?请用python代码阐述为什么?
# x、y、z的变量值相同,在pycharm内存地址相同,python里面不同
x = 257
y = x
z = 257

print(x==y) #True
print(x==z) #True
print(y==z) #True

print(id(x)) #2185720475344
print(id(y)) #2185720475344
print(id(z)) #2185720475344

7. Description of numeric type

Integer

1. Role: ID / telephone number

2, define how

# jzm_id = 360281
jzm_id1 = 360281
# print(jzm_id1)
jzm_id2 = int(360281) 
print(jzm_id2)

3, use

x = 1
y = 2

print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)  # 取余
print(x // y)  # 取整
print(x ** y)  # 幂
#log/sin/cos
import cmath  # python是手机,pip是软件管家,import cmath 打开一个cmath软件
print(cmath.sin(10))
print(cmath.pi)
print(cmath.e)

print(abs(-10)) # 10 绝对值

Float

1. Role: Salary 3.1w

2, define how

salary = 3.2
salary1 = float(3.2)
# 4
height = float(4)  # 4.0  # 强制类型转换
print(height)

salary2 = int(3.7)  # 不会四舍五入
print(salary2)  # 3
#四舍五入
print(round(3.7)) #4

3, use

+ - * / % // **

Logical comparison

x = 1
y = 2
print(x > y)  # False
print(x >= 1)  # True
print(x < y)  # True
print(x <= 1)
print(x != y)
print(x == y)  # 一个=是赋值,2个==是比较

8. Type Description String

1. Role: Name / Sex

2, define how

name='jzm'#单引号内把字符串起来
name="jzm"

height1='nick"s height'  #读取第一个单引号的时候,字符串开始;第二引号结束
height2="nick's height   #碰到第一个双引号,字符串类型,碰到第二双引号

#三单/双引号:换行
pome='''
床前明月光,疑是地上霜;
举头望明月,低头思故乡。
'''
print(pome)

#数据类型的强制转换
height_str=str(180)
print(hegiht_str,type(height_str))

height=int('180')
print(height,type(height)) 

No single quotation marks are variable names

3, use

str1 = 'nick '
str2 = 'handsome'

print(str1 +' ' + str2 ) # 字符串不能和数字相加
print(str1 * 10)

Guess you like

Origin www.cnblogs.com/jzm1201/p/11493711.html