Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Getting started · Lesson 4 of 25

    Type conversion and input

    int, float and str, and why input always returns text.

    7 minutes3 games

    int("42"), float("3.5"), str(99) and bool(0) convert between types. It matters with input(): it reads what the user types and always returns text, even when they type a number.

    Python
    age = input("How old are you? ")   # the user types 20
    print(age + 1)        # TypeError: can only concatenate str to str
    print(int(age) + 1)   # 21
    Python
    print(int("42") + 8)
    print(float("2.5") * 2)
    print("Score: " + str(95))
    print(int(3.99))            # cuts the decimals: 3
    print(bool(""), bool("0"), bool(0), bool([]))
    
    try:
        int("12px")
    except ValueError as e:
        print("ValueError:", e)

    Important

    In Python adding text and a number is an error ("5" + 1 → TypeError); it doesn't join like JavaScript. You must convert yourself.

    falsy values =

    False[0]
    0[1]
    0.0[2]
    ""[3]
    [][4]
    {}[5]
    None[6]

    These count as False in conditions; everything else is True.

    Interview question

    What does int("3.7") return?

    What's the output?

    print(int("7") + int("3"))
    print("7" + "3")

    What will this code print?

    Spot the bug

    One line raises a TypeError. Which?

    Exercise

    Both values arrive as text. Print their sum as a number (30).

    Expected output: 30

    Python
    a = "12"
    b = "18"
    

    Learn more from

    • Python docs: input()docs.python.org
    • Python docs: Truth Value Testingdocs.python.org
    • Real Python: Basic Input and Output in Pythonrealpython.com

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousNumbers and operatorsNextStrings and f-strings
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.