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 8049879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:54:34+00:00 2026-06-05T06:54:34+00:00

Just learned Python 3 in 7 days, and I have the feeling that there’s

  • 0

Just learned Python 3 in 7 days, and I have the feeling that there’s a bit of a hole in my understanding of byte strings. In Python 3, suppose I have a byte string b'1234'. Its iterator returns integers:

Python 3.2.3 (default, May 26 2012, 18:49:27) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> for z in b'1234':
...   print(type(z))
... 
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'> 

I can find an integer in the byte string (the definition of in is that it searches for equality):

>>> 0x32 in b'1234'
True

However, I would like to find the index of a given integer in the byte string. bytes.index requires a substring:

>>> b'1234'.index(b'2')
1

Now, if I have a variable x that I want to find, this is the best I’ve come up with:

>>> x = 0x32
>>> b'1234'.index(bytes([x]))
1

I know Python is more elegant than that. I’m clearly missing something obvious. Any ideas as to a simpler way to do this other than creating a sequence of a single integer? Or is that really it?

  • 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-05T06:54:35+00:00Added an answer on June 5, 2026 at 6:54 am

    Yes, that’s the way to do it.

    It’s not much different from the way to search for a character in a string based on its code point:

    x = 0x32
    i ='1234'.index(chr(x))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just learned about recursion in Python and have completed assignments, one of
I just learned (the hard way) that Java Component s can only have one
I learned about multiprocessing from Python and I'm having a bit of trouble understanding
I have just learned Java in my college. However, in that I can just
I have learned that python does not guarantee that __del__ is called whenever an
I just learned of vim's gf command for navigating to files that are referenced
I am a newbie and just learned that if I define say package my.first.group.here;
I started working in Python just recently and haven't fully learned all the nuts
I just learned that alert() is a method of the window object. I also
I just learned of X-Macros . What real-world uses of X-Macros have you seen?

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.