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

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

Adv 120x600

Looking for advertising?

Consider These Things If You Appreciate What stackorigin Does: Stackorigin is a community where you can ask questions and find answers, for free to everyone. We would appreciate it if you bought us a coffee if you liked what we were doing.

Buy me a Coffe

Adv 120x600

  • Random
  • Answers
    • On: August 30, 2021
    • Answer: 1

    What is supervisor in django

    • On: August 9, 2021
    • Answers: 0

    How to use Multiple Databases with django

    • On: July 31, 2020
    • Answer: 1

    How can I check if the input is empty in ...

    • On: August 5, 2022
    • Answers: 0

    TROUVER! Acheter Caduet en ligne, Caduet indikasi

    • On: February 7, 2023
    • Answers: 0

    mysql Truncate and Drop table

  • strapcart_online
    strapcart_online added an answer Sildenafil citrate is a common ingredient in Cenforce 150mg tablets. This drug… March 21, 2023 at 11:42 am
  • strapcart_online
    strapcart_online added an answer Vilitra 20mg tablets are used to overcome the problem of… March 18, 2023 at 6:13 am
  • ashok
    ashok added an answer Not every girl, there are some girls out there who… March 16, 2023 at 4:15 am
  • strapcart_online
    strapcart_online added an answer Tadarise 40 Tablet is used to permanently remove the problem… March 4, 2023 at 5:48 am
  • strapcart_online
    strapcart_online added an answer Men use Cenforce D tablets for the treatment of sexual… March 1, 2023 at 5:59 am

Adv 120x600

Trending Categories

Health
2041Questions
, 4Followers
Programming
1236Questions
, 0Followers
Technology
216Questions
, 3Followers
General Knowledge
131Questions
, 0Followers
Business & Finance
84Questions
, 4Followers

Adv 120×600

Stats

  • Questions 4k
  • Answers 1k
  • Best Answers 105
  • Users 100

Users

niyadas823

niyadas823

  • 0 Questions
  • 0 Answers
nirala3

nirala3

  • 2 Questions
  • 0 Answers
Perrywalton

Perrywalton

  • 1 Question
  • 0 Answers
veeraa

veeraa

  • 0 Questions
  • 0 Answers
Stewesmitz

Stewesmitz

  • 0 Questions
  • 0 Answers

Adv 120×600

Explore

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

Footer

Stackorigin - The Community of Question and Answers

Stackorigin

Stackorigin is the world’s largest Q&A networking site, Stackorigin community brings you the collaboration of all the various Questions and the related Answers given by the community.

About

  • About Us
  • Contact Us
  • FAQ
  • Submit Guest Post Article on Technology, Education, Health, Apps, Gadgets, IoT, AI, Business, Digital Marketing and More

Info

  • Privacy Policy
  • Terms and Conditions
  • Community Guidelines
  • Tags

Products

  • Tutorials
  • Advertising
  • Categories
  • Corona
  • StackHow

Follow

© 2022 Stackorigin. All Rights Reserved.