Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära 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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 3

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Awesome!

Completion rate improved to 4.55

bookPrint Function in Dart

Svep för att visa menyn

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 3
some-alt