2.2.10

Casting

Test yourself

Casting

Casting is the process of converting data from one type to another.

Illustrative background for Reasons for castingIllustrative background for Reasons for casting ?? "content

Reasons for casting

  • One of the most common reasons for casting is output.
  • Output must be formatted as a string, and so we may need to convert a certain piece of data to a string.
  • All input also comes as a string, and must then be converted to other data types.
Illustrative background for Casting functionsIllustrative background for Casting functions ?? "content

Casting functions

  • Casting to a string can be done using the str function. E.g:
    • str(3) gives "3".
  • Casting to an integer can be done using the int function. E.g:
    • int(3.4) gives 3.
  • Casting to a real can be done using the real function. E.g:
    • real("3.4") gives 3.4.

Jump to other topics

1Computer Systems

1.1Systems Architecture

1.2Memory & Storage

1.3Computer Networks, Connections & Protocols

1.4Network Security

1.5Systems Software

1.6Ethical, Legal, Cultural & Environmental Concern

2Computational Thinking, Algorithms and Programming

2.1Algorithms

2.2Programming Fundamentals

2.3Producing Robust Programs

2.4Boolean Logic

2.5Programming Languages & IDEs

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson