• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • 0.11.0 /
      • Expressions /
      • F-String Expression
    Kipper Docs
    • next
    • latest
    • 0.11.0
    • 0.10.4
    • 0.9.2
    • Overview

    • Quickstart

    • Goals for Kipper

    • Supported platforms

    • Usage Examples

      • Overview

      • Compiler Setup

        • Overview

          • index

          • compiler

          • errors

          • logger

          • utils

          • config

          • index

          • index

        • Overview

        • new

        • run

        • compile

        • help

        • version

    • Variables

      • Overview

      • String Type

      • Number Type

      • Boolean Type

      • Void Type

      • Null Type

      • Undefined Type

      • Array Type

      • Overview

      • Arithmetic Expression

      • Assignment Expression

      • Conditional Expressions

      • Logical Expressions

      • Bitwise Expression

      • Relational Expressions

      • Convert Expression

      • F-String Expression

      • Member Access Expression

      • Function Call Expression

      • Overview

      • Expression Statement

      • If Statement

      • While Loop

      • Do-While Loop

      • For Loop

      • Compound Statement

      • Jump Statement

    • Functions

    • Comments

    • Built-in Functions

      • 0.11.0 /
      • Expressions /
      • F-String Expression
    • 0.11.0 /
    • Expressions /
    • F-String Expression

    Edit page

    F-String Expression

    F-String Expression is a string literal that is prefixed with f. It may contain replacement fields, which are expressions delimited by curly braces {}.

    This is the Kipper variant of templating/string formatting. It works by evaluating the expression inside the curly braces and replacing the curly braces and the expression with the result of the evaluation.

    f"Hello {name}!"

    The above expression will be evaluated to Hello World! if name is World.

    Syntax

    The syntax of F-String Expression is as follows:

    f"STR{EXP}STR";

    Every expression inside the curly braces will be evaluated and replaced with the result of the evaluation. The rest of the string will be left as is. Expressions may appear anywhere in the string, including the beginning and the end.

    Examples

    String Formatting

    var name: str = "Luna";
    var age: num = 20;
    print(f"Hello {name}! You are {age} years old.");

    Simplified String Concatenation

    var welcome: str = "Hello ";
    var name: str = "World";
    print(f"{welcome}{name}");

    Using Expressions in F-Strings

    var name: str = "user";
    var age: num = 20;
    print(f"Hello {name}! You are {age} years old. Next year you will be {age + 1} years old.");

    Using F-Strings in F-Strings (Nested Expressions)

    def printWelcome(name: str, age: num) -> void {
        var olderKeyword: str = "adult";
        var youngerKeyword: str = "child";
        print(f"Hello {name}! {age > 18 ? f"You are an {olderKeyword}." : f"You are a {youngerKeyword}."}");
    }
    
    var name: str = "Luna";
    var age: num = 20;
    printWelcome(name, age);
  • Developed at:

    • Releases
    • GitHub
    • Security
    • Issue Tracker
    • License
  • Copyright © 2021-2025 Luna Klatzer, 2024-2025 Lorenz Holzbauer & Fabian Baitura.
    Kipper is licensed under the GPL-3.0-or-later license.