Print Function in Dart
To display information in the console, add text inside the parentheses of the print()
function.
main.dart
123void 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
123456void 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
123void 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.
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 4.55
Print Function in Dart
Свайпніть щоб показати меню
To display information in the console, add text inside the parentheses of the print()
function.
main.dart
123void 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
123456void 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
123void 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.
Дякуємо за ваш відгук!