![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we unpack a string of integers to complex numbers in Python?
A string contains two integers separated by comma. It is first split in a list of two strings having digits.
>>> s="1,2".split(",") >>> s ['1', '2']
Two items are then converted to integers and used as arguments for complex() function
>>> complex(int(s[0]), int(s[1])) (1+2j)
This results in unpacking of string of integers in a complex number
Advertisements