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 question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

Stackorigin – The Community of Question and Answers

Stackorigin – The Community of Question and Answers Logo Stackorigin – The Community of Question and Answers Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question

Type Casting

Type Casting nothing but converting one data type to other data type.

Int: Converting float, Bool, Str type to Int type.

  • Convert Float type to Int type: int(10.5) => 10
  • Convert Bool type to Int type: int(True) => 1
  • Convert Bool type to Int type: int(False) => 0
  • Convert Str type to Int type: int(“10”) => 10
  • Convert Str type to Int type: int(“10.5”) => Value Error will get, if we want convert Str type to Int, string should be decimal.
  • Convert complex type to Int type: int(10+20j) => Type Error will get

Float: Converting int, Bool, Str type to Float type.

  • Converting Int type to Float type: float(10) => 10.0
  • Converting Bool (True) type to Float type: float(True) => 1.0
  • Converting Bool (False) type to Float type: float(False) => 0.0
  • Converting Str type to Float type: float(“10”) => 10.0
  • Converting Str type to Float type: float(“10.5”) => 10.5
  • Converting Complex type to Float type: float(10 + 20j) => cant convert complex to float.

Complex: we can convert other type to complex type.its 2 form’s are there.

form1: complex(x) => x + 0j

form2: complex(x,y) => x + yj

form1:

  • Converting Int type to Complex type: complex(10) => 10 + 0j
  • Converting Float type to Complex type: complex(10.5 ) => 10.5 + 0j
  • Converting Str type to Complex type: complex(“10” ) => 10 + 0j
  • Converting Str type to Complex type: complex(“10.5” ) => 10.5 + 0j

form2:

  • Converting Int type to Complex type: complex(10,20) => 10 + 20j
  • Converting Bool type to Complex type: complex(True, False) => 1+ 0j
  • Converting Str type to Complex type: complex(“10”, “20”) => complex() cant take arg if first is a string.

Bool: we can convert one data type to bool type.

  • Converting Int type to Bool type: bool(0) => False
  • Converting Int type to Bool type: bool(1) => True
  • Converting Int type to Bool type: bool(-100) => True (Except 0 Remaining all True)
  • Converting Float type to Bool type: bool(0.0) => False
  • Converting Float type to Bool type: bool(0.1) => True
  • Converting Complex type to Bool type: bool(10 + 20j) => True
  • Converting Complex type to Bool type: bool(0 + 0j) => False
  • Converting Str type to Bool type: bool(“) => False
  • Converting Str type to Bool type: bool(“stackorigin) => True
  • Converting Str type to Bool type: bool(” “) => True

Str: we can perform any type

  • Converting Int type to Str type: str(100) => “100”
  • Converting Bool type to Str type: str(True) => “True”
  • Converting Complex type to Str type: str(10+20j) => “(10+20j)”
Share
  • Facebook

Sidebar

Ask A Question

Stats

  • Questions 403
  • Answers 279
  • Best Answers 34
  • Users 42

Adv 120x600

  • Recent
  • Answers
  • ashok

    Is it better to buy fruit and vegetables at the

    • 0 Answers
  • ashok

    Can Lemon stop vomiting?

    • 0 Answers
  • pratap

    How does break, continue and pass work in python?

    • 0 Answers
  • sam

    What is self in Python?

    • 0 Answers
  • arjun

    What is the best career to study in USA?

    • 0 Answers
  • forecastadvertising
    forecastadvertising added an answer Forecast Advertising is one of the top advertising agency. At… March 5, 2021 at 5:12 pm
  • hari
    hari added an answer Best way to earn money from home: Online tutoring Rent… March 1, 2021 at 6:15 pm
  • hari
    hari added an answer Many natural scents that are appealing to humans actually repel… March 1, 2021 at 6:12 pm
  • hari
    hari added an answer YES Quora is always Secure. March 1, 2021 at 6:11 pm
  • hari
    hari added an answer United States is by far the most famous country in… March 1, 2021 at 6:11 pm

Top Members

forecastadvertising

forecastadvertising

  • 0 Questions
  • 1 Answer
deerikaexpress

deerikaexpress

  • 0 Questions
  • 3 Answers
murlijha

murlijha

  • 2 Questions
  • 0 Answers
Harish

Harish

  • 0 Questions
  • 1 Answer
NBar Nail Salon

NBar Nail Salon

  • 0 Questions
  • 1 Answer

Trending Categories

Programming
104Questions
, 0Followers
Technology
68Questions
, 3Followers
General Knowledge
30Questions
, 0Followers
Electronics & Computers
29Questions
, 0Followers
Health
28Questions
, 3Followers

Adv 234x60

Trending Tags

china (4) computer (9) django (11) game (4) git (7) google (12) health (9) html (4) india (16) javascript (5) job (5) laptop (5) life (4) list (5) mobile (5) python (28) software (5) time (4) usa (15) website (4) youtube (4)

Adv 120x600

Adv 120x600

Adv 120x600

Explore

  • Recent Questions
  • Most Answered
  • Answers
  • No Answers
  • Most Visited
  • Most Voted
  • Random

Footer

Stackorigin - The Community of Question and Answers

Stackorigin

Stackorigin is world’s largest Q&A networking site. Stackorigin stands for “Stack” means Group of Answers found for the bunch of questions and “Origin” means From the beginning.

About

  • About Us
  • Contact Us
  • FAQ
  • Corona

Info

  • Categories
  • Community Guidelines
  • Tags

Products

  • Tutorials

Follow

© 2021 Stackorigin. All Rights Reserved.