HSHimanshu Sharma
Basic Python Full Course

Python Full Course | Episode 5: Base Conversions

Advertisement

Base conversions:

—---------------------

  1. bin() {to convert the value from any base to binary}

bin(15)

‘0b1111’

  1. oct() {you can convert any value from any base to octal }

oct(786)

‘0o175316’

  1. hex() {from any base to hexadecimal}

hex(10)

‘0xa’

Float data  type:

—------------------

  1. x = 20.3 

Complex data type:

—----------------------

a+bj

a = real part (a part should be anything)

b = imaginary part  (this part should be compulsory decimal)

j^2 = -1

For example,

x = 10+20j

type(x)

<class ‘ complex ‘>

“j should be compulsory after the b symbol”

>>>>a = 10+20j

>>>>b = 20+30j

>>>>a+b 

>>>>(30+50j)

Bool data type:

—-----------------

We use this datatype to represent boolean values.

What are the allowed values in boolean datatypes?

 >> True and False 

For example:

b = true 

type(b)

<class ‘ bool’>

a = 10 

b = 20 

c = a<b

c 

Output: True

True + True => 2

True + False => 1

In python internally True is represented by 1 and False is represented by 0.

str:

—-

In python, any sequence of characters is considered as str.

s  =’‘himanshu’’ 

type(s)

<class ‘str’>

s =”""Himanshu

            Sharma”""

print(s)

{this is a multiline string}

Advertisement