Python3基础 内置函数 eval str转为list tuple dict
- Python : 3.7.3
- OS : Ubuntu 18.04.2 LTS
- IDE : pycharm-community-2019.1.3
- Conda : 4.7.5
- typesetting : Markdown
code
"""
@Author : 行初心
@Date : 2019/7/7
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
# eval会把字符串的内容 当做 有效的表达式
# 信息安全 -> eval不要直接执行用户的输入内容
# 字符串的格式得对
# txt文本存储 数据信息 -> 读取 转换 应用
# str -> list
print(eval("['地浆','阿井泉','盐胆水']"), type(eval("['地浆','阿井泉','盐胆水']")))
# str -> tuple
print(eval("(1,2,3,4)"), type(eval("(1,2,3,4)")))
# str -> dict
print(eval("{'子':'鼠','丑':'牛','寅':'虎'}"), type(eval("{'子':'鼠','丑':'牛','寅':'虎'}")))
if __name__ == '__main__':
main()
result
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/Base/demo.py
['地浆', '阿井泉', '盐胆水'] <class 'list'>
(1, 2, 3, 4) <class 'tuple'>
{'子': '鼠', '丑': '牛', '寅': '虎'} <class 'dict'>
Process finished with exit code 0
source_code
def eval(*args, **kwargs): # real signature unknown
"""
Evaluate the given source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
"""
pass
resource
- [文档 - English] docs.python.org/3
- [文档 - 中文] docs.python.org/zh-cn/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 内置函数 eval str转为list tuple dict的更多相关文章
- 2.1 Python3基础-内置函数(print&input)
>>返回主目录 源代码 # 内置函数:输入/输出 name = 'Portos' age = 18 sex = 'man' score = 99.5 print('Hello World! ...
- Python3基础 内置函数 dir 查询对象的方法列表
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 内置函数 id
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 内置函数 hash
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- python基础——内置函数
python基础--内置函数 一.内置函数(python3.x) 内置参数详解官方文档: https://docs.python.org/3/library/functions.html?highl ...
- python3.7 内置函数整理
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 内置函数整理 #abs(x) #返回数字的绝对值. 参数可以是整 ...
- python3.7内置函数整理笔记
#python3.7 内置函数整理 #abs(x) #返回数字的绝对值. 参数可以是整数或浮点数. 如果参数是复数,则返回其大小 # print(abs(1)) # print(abs(-1)) # ...
- 内置函数——eval、exec、compile
内置函数——eval.exec.compile eval() 将字符串类型的代码执行并返回结果 print(eval('1+2+3+4')) exec()将自字符串类型的代码执行 print(exec ...
- Python基础-内置函数总结
内置函数 int('123') float() string() tuple() set() dict(name='zdd',age=18) type()#查看类型 len()#看长度,其实是元素的个 ...
随机推荐
- k8s 挂载卷介绍(四)
kubernetes关于pod挂载卷的知识 首先要知道卷是pod资源的属性,pv,pvc是单独的资源.pod 资源的volumes属性有多种type,其中就包含有挂载pvc的类型.这也帮我理清了之间的 ...
- java8中日期字符串的月日时分秒自动补零
需求:如字符串2019-7-1 9:6:5转成2019-07-01 09:06:05 java8实现如下: public static String getStartDate(String start ...
- Feign 报错:The bean 'service-producer.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
报错: 2019-09-17 20:34:47.635 ERROR 59509 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ******* ...
- 12、Python函数高级(命名空间、作用域、装饰器)
一.名称空间和作用域 1.命名空间(Namespace) 命名空间是从名称到对象的映射,大部分的命名空间都是通过 Python 字典来实现的. 命名空间提供了在项目中避免名字冲突的一种方法.各个命名空 ...
- GPU的主要工作:图像合成、图形操作、光线表达
GPU的主要工作:图像合成.图形操作 gpu不产生图片, 只表达和处理图片.图形:
- Codechef August Challenge 2019 Chef and Gordon Ramsay
[传送门] 题目即求所有的三元组,相对大小关系同 $p_1,p_2,p_3$. 题解说都很清楚,这里写一下过程整理一下思路. 如果我们枚举中间这个元素,那么就是统计子树内外有多少个大于这个数和小于这个 ...
- RookeyFrame 整个运行流程
准备开始整理一下这个项目的整体框架,很久没研究这个框架了,心里还是念着的,今儿乘有时间弄一下. 一丁点建议: 先自己一个一个的搬作者的类库,这样就能很好的理解作者的项目结构 每搬一个类库都运行一下哦, ...
- [RN] React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示
React Native中使用 react-native-scrollable-tab-view嵌套在ScrollView里,导致 子内容 在安卓上无法显示 问题: 0.9.0 或 0.8.0 版本的 ...
- 模拟测试20191017~18 lrd Day1& Day2
$Day1:$ $T1:位运算$ 从低位到高位分类讨论就好了 记得判$inf$ $T2:集合论$ 考场上差点就打线段树了 用一个数组维护,同时用一个变量代表当前总体$+$&&$-$的值 ...
- Shared Virtual Memory (SVM) Functions
Description Shared Virtual Memory (SVM) (Glossary): An address space exposed to both the host and th ...