Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:33:08+00:00 2026-06-01T17:33:08+00:00

This one is hopefully simple, I have a string voltage is E=200V and the

  • 0

This one is hopefully simple, I have a string “voltage is E=200V and the current is I=4.5A”. I need to extract both float values. I have tried to use the float() function (with a sub-string of 11 to 16 in the parameters) but i get an error. I realize this probably is not good coding, I am in the beginning stages of trying to learn Python. Any help is much appreciated.

edit: Here is the code

I = 0.0     
if((currentString.find('I=')) != -1):
            I = float(currentString[(currentString.find('I=')):(currentString.find('A'))])

again, im new to this language and i know that looks ugly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:33:09+00:00Added an answer on June 1, 2026 at 5:33 pm

    I’m reluctant to mention regular expressions, as it is often a confusing tool for novices, but for your use and reference, here is a snippet that should help you get those values. IIRC voltage is unlikely to be float(instead int?), so this matching operating returns int later, but can be float if that is really required.

    >>> import re
    >>> regex = re.compile(r'.*?E=([\d.]+).*?I=([\d.]+)')
    >>> re.match('voltage is E=200V and the current is I=4.5A')
    >>> matches = regex.match('voltage is E=200V and the current is I=4.5A')
    >>> int(matches.group(1))
    200
    >>> float(matches.group(2))
    4.5
    

    A method to extract such numbers using more simple tools is:

    >>> s.find('E=')
    11
    >>> s.find('V', 11)
    16
    >>> s[11:16]
    'E=200'
    >>> s[11+2:16]
    '200'
    >>> int(s[11+2:16])
    200
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should hopefully be a simple one. I would like to add an extension
This should hopefully be a simple one. When using a date time picker in
Hopefully this is a simple one, but can anyone provide some simple c# code
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
This will hopefully be an easy one. I have an F# project (latest F#
Hopefully this is a really quick one ;) I have written a lexer /
Hopefully this is less complex than I think. I have one table of companies,
This is hopefully a very simple question, but one a lot of Googling has
hopefully this should be a quick and simple one, using PHP I'm trying to
hopefully a simple question here, i have a barcode scanner using Zxing, this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.