您当前的位置: 首页 >  Python
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python编程语言学习:利用locals函数判断某个变量参数之前是否已经被定义/存在/出现

一个处女座的程序猿 发布时间:2021-03-30 19:33:39 ,浏览量:0

Python编程语言学习:利用locals函数判断某个变量参数之前是否已经被定义/存在/出现

 

 

 

目录

利用locals函数判断某个变量参数之前是否已经被定义/存在/出现

输出结果

实现代码

 

 

 

利用locals函数判断某个变量参数之前是否已经被定义/存在/出现 输出结果

RangeIndex: 768 entries, 0 to 767
Data columns (total 9 columns):
 #   Column                    Non-Null Count  Dtype  
---  ------                    --------------  -----  
 0   Pregnancies               768 non-null    int64  
 1   Glucose                   768 non-null    int64  
 2   BloodPressure             768 non-null    int64  
 3   SkinThickness             768 non-null    int64  
 4   Insulin                   768 non-null    int64  
 5   BMI                       768 non-null    float64
 6   DiabetesPedigreeFunction  768 non-null    float64
 7   Age                       768 non-null    int64  
 8   Outcome                   768 non-null    int64  
dtypes: float64(2), int64(7)
memory usage: 54.1 KB
None
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'plt', 'pd', 'data_frame', 'col_label', 'cols_other', 'data_X', 'data_y_label_μ'])
data_X
data_y_label_μ
data_dall02
data_dall02 not in locals().keys()!

 

 

 

实现代码
# Python编程语言学习:利用locals函数判断某个变量参数之前是否已经被定义/存在/出现
import pandas as pd

data_frame=pd.read_csv('data_csv_xls\diabetes\diabetes.csv')

col_label='Outcome'
cols_other=['Pregnancies','Glucose','BloodPressure','SkinThickness','BMI']
data_X=data_frame[cols_other]
data_y_label_μ=data_frame[col_label]



# 判断某个参数之前是否已经被定义/存在/出现
print(locals().keys())
param_lists=['data_X','data_y_label_μ','data_dall02']
for param in param_lists:
    print(param)
    if param not in locals().keys():
        print('%s not in locals().keys()!'%param)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0451s