What is the use of eval in Python?

藏色散人
Release: 2019-07-01 09:39:48
Original
4519 people have browsed it

What is the use of eval in Python?

What is the use of eval in Python?

The eval function is to convert list, dict, tuple and str.

The str function converts list, dict, tuple into strings

1. Convert string to list

a = =(b)
Copy after login

2. Convert string to dictionary

a = "{1: 'a', 2: 'b'}"print(type(a))
b = eval(a)print(type(b))print(b)
Copy after login

3. Convert strings into tuples

a = "([1,2], [3,4], [5,6], [7,8], (9,0))"print(type(a))
b=eval(a)print(type(b))print(b)
Copy after login

Related recommendations: "Python Tutorial"

The above is the detailed content of What is the use of eval in Python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!