PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Type Casting in Python

← All stacks

Theory

16/268

Type Casting in Python

Type casting changes a value’s type. int("10") → 10. str(10) → "10". float("3.5") → 3.5. list("Asha") → ['A','s','h','a']. bool(0) is False; bool("Asha") is True. Empty "", [], {}, None are falsy.

Bad text fails: int("hi") → ValueError. bool rules show up in if conditions more than in explicit bool() calls. Show one valid cast and one failing cast in the viva.

Type Casting in Python — output — 22 then 100 marks. "21" became int; 100 became str for join.

Exam tip

Valid cast + failing cast + falsy list.

Example

# Type casting
n = int("21")
print(n + 1)
print(str(100) + " marks")

Type Casting in Python — output: 22 then 100 marks. "21" became int; 100 became str for join.

Short notes

  • Defint() float() str() bool().
  • RuleFalsy: 0 "" [] None.
  • Trapint("hi") → ValueError.

Questions

1

Explain Type Casting as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Type Casting?

Previous← Python NumbersNextPython Strings →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.