Зміст курсу
Introduction to Dart
Introduction to Dart
Function print()
Let's take a detailed look at how to use the print()
function:
Print with Text
main
void main() { print("Text you want to output"); }
After starting, the program prints information to the console from the parentheses of the print()
function.
If we want to output the text to the console, we must write it inside the quotation marks.
main
void main() { print('Hi, Codefinity!'); print("I want know more"); }
Rules
The text can be written in single quotation marks:
The text also can be written in double quotation marks:
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 Python 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.
Print with Numbers
Working with numbers is different from working with text. Suppose you want to display numbers. Since we work with number values, you don't need to use quotes (" "
or ' '
).
main
void main() { print(2); }
We will consider working with numbers and mathematical operations in detail in Chapter 5.
Дякуємо за ваш відгук!