Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Print Function in Dart | First Acquaintance with Dart
Introduction to Dart

bookPrint Function in Dart

To display information in the console, add text inside the parentheses of the print() function.

main.dart

main.dart

copy
123
void main() { print("Text you want to output"); }

If you want to output the text to the console, we must write it inside the quotation marks.

main.dart

main.dart

copy
123456
void main() { // The text can be written in single quotation marks print('Hi, Codefinity!'); // The text also can be written in double quotation marks print("I want know more"); }

The main rule when using the print() function is that it's important for the quotation marks surrounding the text to match on both sides. For example, if we use single quotes to print text ('like this'), we must close them with single quotes as well. This allows Dart to correctly recognize it as text to be printed, rather than a variable name or instruction. If the quotation marks do not match, or if they are absent altogether, it can lead to a runtime error in the program.

main.dart

main.dart

copy
123
void main() { print(2); }

Working with numbers differs from working with text. When displaying numbers, you don’t need to use quotes (" " or ' '), because numbers are treated as numeric values, not text.

question mark

Which statement correctly uses print() to display text or a number in Dart?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 3

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Awesome!

Completion rate improved to 4.55

bookPrint Function in Dart

Scorri per mostrare il menu

To display information in the console, add text inside the parentheses of the print() function.

main.dart

main.dart

copy
123
void main() { print("Text you want to output"); }

If you want to output the text to the console, we must write it inside the quotation marks.

main.dart

main.dart

copy
123456
void main() { // The text can be written in single quotation marks print('Hi, Codefinity!'); // The text also can be written in double quotation marks print("I want know more"); }

The main rule when using the print() function is that it's important for the quotation marks surrounding the text to match on both sides. For example, if we use single quotes to print text ('like this'), we must close them with single quotes as well. This allows Dart to correctly recognize it as text to be printed, rather than a variable name or instruction. If the quotation marks do not match, or if they are absent altogether, it can lead to a runtime error in the program.

main.dart

main.dart

copy
123
void main() { print(2); }

Working with numbers differs from working with text. When displaying numbers, you don’t need to use quotes (" " or ' '), because numbers are treated as numeric values, not text.

question mark

Which statement correctly uses print() to display text or a number in Dart?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 3
some-alt