Session 1: Introduction To Python Programming

Hello everyone!

Use this thread to ask questions about topics covered in Session 1.

General rules to follow:

  • Indicate the quiz or exercise name at the beginning of your post.

  • Write down your question in as much detail as you possibly can.

  • If your question involves code, please include it in code blocks below with comments and avoid posting screenshots.

The following strings can be prepended to an integer value to indicate a base other than 10:

Prefix Interpretation Base

0b (zero + lowercase letter 'b')
0B (zero + uppercase letter 'B') Binary 2

0o (zero + lowercase letter 'o')
0O (zero + uppercase letter 'O') Octal 8

0x (zero + lowercase letter 'x')
0X (zero + uppercase letter 'X') Hexadecimal16

Can any TA may be help me understand this ?

Hello Manish,

In computer programming, numbers can be represented in different base systems, such as binary, octal, and hexadecimal. These base systems have different digit sets and conventions for representing numbers.

  1. Binary (Base 2):
    Binary is a base-2 number system, which means it only uses two digits: 0 and 1. In binary, each digit represents a power of 2. The prefixes used to indicate a binary number are “0b” or “0B”. For example, if you see the number “0b1101”, it represents the binary number 1101, which is equivalent to the decimal number 13.
  2. Octal (Base 8):
    Octal is a base-8 number system, which means it uses eight digits: 0, 1, 2, 3, 4, 5, 6, and 7. In octal, each digit represents a power of 8. The prefixes used to indicate an octal number are “0o” or “0O”. For example, if you see the number “0o17”, it represents the octal number 17, which is equivalent to the decimal number 15.
  3. Hexadecimal (Base 16):
    Hexadecimal is a base-16 number system, which means it uses sixteen digits: 0-9 and A-F (where A represents 10, B represents 11, and so on up to F, which represents 15). Hexadecimal is commonly used in computer programming, especially for representing memory addresses and binary data. In hexadecimal, each digit represents a power of 16. The prefixes used to indicate a hexadecimal number are “0x” or “0X”. For example, if you see the number “0x3F”, it represents the hexadecimal number 3F, which is equivalent to the decimal number 63.

By using these prefixes, you can explicitly indicate the base of a number when working with different programming languages or systems that support multiple number bases. It helps to avoid confusion and ensures that the correct interpretation of the number is maintained.

Hope this helps.
Thanks & Regards,
Nawang