PythonPython · Chapterبەش 3 · Lectureوانە 3.2
Your First Program: print() and Commentsیەکەم بەرنامە: print() و لێدوانەکان
Write and run your first Python program: how print() shows text and numbers, why text needs straight quotes, how several values are printed, why the order of lines, capital letters and spaces matter, and how to write good comments with # (and why triple quotes are not comments).
یەکەم Python بنووسە و جێبەجێی بکە: print() چۆن دەق و ژمارە پیشان دەدات، بۆچی دەق پێویستە، چۆن چەند چاپ دەکرێن، بۆچی ڕیزبەندیی دێڕەکان، پیتی گەورە و گرنگن و چۆن باش بە # بنووسیت (و بۆچی سێ نین).
What you will learnچی فێر دەبیت
- Write and run a program that prints text, numbers and several values with
print(). - Use straight quotation marks correctly and explain why curly quotes fail.
- Explain that Python checks the whole file, then runs one statement per line from top to bottom, and that it is case-sensitive and uses indentation.
- Write useful comments with
#and tell a comment from a triple-quoted string.
- بنووسیت و جێبەجێی بکەیت کە بە
print()دەق، ژمارە و چەند چاپ دەکات. - بە دروستی بەکار بهێنیت و ڕوونی بکەیتەوە بۆچی شکست دەهێنن.
- ڕوونی بکەیتەوە کە Python سەرەتا هەموو فایلەکە دەپشکنێت، پاشان لە سەرەوە بۆ خوارەوە لە هەر دێڕێکدا یەک جێبەجێ دەکات، هەروەها و بەکار دەهێنێت.
- بەسوود بە
#بنووسیت و لە بە سێ جیا بکەیتەوە.
Your first programیەکەم بەرنامەکەت
Since the 1970s programmers have had a tradition: the first program in a new language shows the words Hello, World! on the screen. In Python this program is a single line. Save it as hello.py and run it (F5 in IDLE, or python hello.py in the terminal, as in Welcome to Python).
لە ساڵانی 1970ـەوە نەریتێکیان هەیە: یەکەم لە زمانێکی نوێدا وشەکانی Hello, World! لەسەر شاشە پیشان دەدات. لە Pythonـدا ئەم بەرنامەیە تەنها یەک دێڕە. بە ناوی hello.py پاشەکەوتی بکە و جێبەجێی بکە (F5 لە IDLE، یان python hello.py لە ، وەک لە بەخێربێیت بۆ Python).
print("Hello, World!")Hello, World!
Python read the line, saw the word print, and showed the text between the quotation marks. The quotation marks themselves are not shown: they only tell Python where the text starts and ends.
Python دێڕەکەی خوێندەوە، وشەی printـی بینی و ئەو دەقەی پیشان دا کە لە نێوان بوو. خودی پیشان نادرێن: تەنها بە Python دەڵێن دەقەکە لە کوێ دەست پێ دەکات و لە کوێ کۆتایی دێت.
Python reads .py files as UTF-8, a way of storing text that covers every alphabet. So Kurdish text works in your programs too:
Python فایلەکانی .py بە UTF-8 دەخوێنێتەوە، کە ڕێگایەکی هەڵگرتنی دەقە و هەموو ئەلفوبێیەک دەگرێتەوە. بۆیە دەقی کوردیش لە کار دەکات:
print("Hello, World!")
print("سڵاو، جیهان!")Hello, World! سڵاو، جیهان!
What print() doesprint() چی دەکات
print is a : a small ready-made program inside Python that does one job. Its job is to write a message to the screen, or more exactly to the program's standard output. That is normally the screen, but it can also be a file or another program.
print : ئامادەی بچووکە لەناو Pythonـدا کە یەک کار دەکات. کارەکەی نووسینی پەیامێکە بۆ سەر شاشە، یان بە وردی بۆ ستانداردی . ئەوە بە شێوەی ئاسایی شاشەیە، بەڵام دەکرێت فایلێک یان بەرنامەیەکی تریش بێت.
To use a function you call it: write its name and then parentheses. What you put inside the parentheses is the , the value you give the function to work with. So the general form is print(something).
بۆ بەکارهێنانی بانگی دەکەیت: ناوەکەی دەنووسیت و پاشان کەوانە. ئەوەی دەیخەیتە ناو کەوانەکانەوە : ئەو دەیدەیت بە بۆ ئەوەی کاری پێ بکات. بۆیە شێوە گشتییەکەی print(something)ـە.
print() callبەشەکانی بانگکردنی print()CêITThe message does not have to be text. It can be a number, a decimal number, True or any other value: print() first turns the value into text, then writes it.
پەیامەکە پێویست ناکات دەق بێت. دەکرێت ژمارە، ، True یان هەر تر بێت: print() سەرەتا دەگۆڕێت بۆ دەق و پاشان دەینووسێت.
print("Hello World")
print(42)
print(3.5)
print(True)Hello World 42 3.5 True
In Kurdish: the first Python code, showing output on the screen with print().
بە کوردی: یەکەم کۆدی ، پیشاندانی لەسەر بە print().
Kurdish video: your first code and print().
ڤیدیۆیەکی کوردی: یەکەم کۆدت و print().
Text needs quotation marksدەق نیشانەکانی گوتەی پێویستە
A piece of text in a program is called a . You write it between quotation marks. Double quotes "…" and single quotes '…' mean exactly the same; just start and end with the same kind. To put one kind of quote inside the text, wrap the text in the other kind.
پارچە دەقێک لە پێی دەڵێن . لە نێوان دەینووسیت. جووتەگوتە "…" و تاکەگوتە '…' ڕێک یەک واتایان هەیە؛ تەنها بە هەمان جۆر دەست پێ بکە و کۆتایی پێ بهێنە. بۆ دانانی جۆرێکیان لەناو دەقەکەدا، دەقەکە بە جۆرەکەی تر دەوری بدە.
print("Double quotes work.")
print('Single quotes work too.')
print("It's easy to put ' inside double quotes.")
print('She said "Silav!" to the class.')Double quotes work. Single quotes work too. It's easy to put ' inside double quotes. She said "Silav!" to the class.
Without quotes, Python does not see text. It thinks the word is the name of something, finds nothing with that name and stops:
بەبێ ، Python دەق نابینێت. وا دەزانێت وشەکە ناوی شتێکە، هیچ شتێک بەو ناوە نادۆزێتەوە و ڕادەوەستێت:
print(Hello)Traceback (most recent call last):
File "/Users/aram/python/no_quotes.py", line 1, in <module>
print(Hello)
^^^^^
NameError: name 'Hello' is not definedQuotes also decide whether something is a number or text. Python calculates 7 + 3, but "7 + 3" is just five characters of text:
هەروەها بڕیار دەدەن شتێک ژمارەیە یان دەق. Python 7 + 3 دەژمێرێت، بەڵام "7 + 3" تەنها پێنج دەقە:
print(7)
print("7")
print(7 + 3)
print("7 + 3")7 7 10 7 + 3
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
Both lines show 7, but the first is a number and the second is text. The difference matters in Variables and data types.
هەردوو دێڕ 7 پیشان دەدەن، بەڵام یەکەمیان ژمارەیە و دووەمیان دەق. ئەم جیاوازییە لە گۆڕاوەکان و جۆرەکانی دراوە گرنگە.
Text needs quotation marksدەق نیشانەکانی گوتەی پێویستە
Straight quotes onlyتەنها نیشانەی گوتەی ڕاست
Word processors and phone keyboards often change " into curly quotes “ ” to make text look nicer. Python does not accept curly quotes. The program below was typed in a word processor:
نووسین و کیبۆردی مۆبایل زۆرجار " دەگۆڕن بۆ “ ” بۆ ئەوەی دەقەکە جوانتر دەربکەوێت. Python قبووڵ ناکات. ئەم بەرنامەیەی خوارەوە لە نووسیندا نووسراوە:
print(“Hello World”) File "/Users/aram/python/curly.py", line 1
print(“Hello World”)
^
SyntaxError: invalid character '“' (U+201C)Real Python 3.12 message. The folder path is the one on your computer.
پەیامی ڕاستەقینەی Python 3.12. ئەوەیە کە لەسەر هەیە.
The fix is to type the quotes again in a code editor (IDLE, Thonny, VS Code), which always gives straight quotes. If you write code on a phone, switch off smart quotes or smart punctuation in the keyboard settings.
چارەسەرەکە ئەوەیە لە دەستکاریکەرێکی کۆددا (IDLE، Thonny، VS Code) دووبارە بنووسیتەوە، کە هەمیشە دەدات. ئەگەر لەسەر مۆبایل کۆد دەنووسیت، smart quotes یان smart punctuation لە ڕێکخستنەکانی بکوژێنەوە.
Printing several valuesچاپکردنی چەند نرخێک
You can give print() several arguments separated by commas. It prints them on one line with one space between them. Every print() then ends its line, so the next print() starts on a new line. An empty print() prints just an empty line.
دەتوانیت چەند بدەیت بە print() کە بە کۆما لێک جیا کرابنەوە. لەسەر یەک دێڕ چاپیان دەکات و یەک دەخاتە نێوانیانەوە. پاشان هەر print()ـێک دێڕەکەی کۆتایی پێ دەهێنێت، بۆیە print()ـی دواتر لە دێڕێکی نوێوە دەست پێ دەکات. print()ـی بەتاڵ تەنها دێڕێکی بەتاڵ چاپ دەکات.
print("Name:", "Shilan")
print("Age:", 19)
print("Marks:", 85, 90, 78)
print()
print("The empty print() above made a blank line.")Name: Shilan Age: 19 Marks: 85 90 78 The empty print() above made a blank line.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Text and a number can be mixed: commas keep them apart and
print()adds the spaces.دەق و ژمارە دەکرێت تێکەڵ بکرێن: کۆماکان لێکیان جیا دەکەنەوە و
print()زیاد دەکات.- Lineدێڕی 4
An empty
print()gives an empty line.print()ـی بەتاڵ دێڕێکی بەتاڵ دەدات.
Python runs your program from top to bottomPython بەرنامەکەت لە سەرەوە بۆ خوارەوە جێبەجێ دەکات
A program is a list of : complete instructions such as print("Hi"). In Python you normally write one statement per line, with no semicolon at the end. Python carries them out in order, from the first line to the last, so the order of your lines is the order of the output.
زنجیرەیەکە لە : فەرمانی تەواوی وەک print("Hi"). لە Pythonـدا بە شێوەی ئاسایی لە هەر دێڕێکدا یەک دەنووسیت، بەبێ لە کۆتاییدا. Python بە ڕیز جێبەجێیان دەکات، لە یەکەم دێڕەوە تا دوایین دێڕ، بۆیە ڕیزبەندیی دێڕەکانت ڕیزبەندیی .


# Tea-house order
print("Two teas, please.")
print("One with sugar.")
# print("And a cake.")
print("Thank you!")Two teas, please. One with sugar. Thank you!
Two statements on one line are a mistake unless you separate them with ;. Python allows print("A"); print("B"), but the style guide PEP 8 asks for one statement per line, because it is easier to read.
دوو لەسەر یەک دێڕ هەڵەیە، مەگەر بە ; لێکیان جیا بکەیتەوە. Python ڕێگە بە print("A"); print("B") دەدات، بەڵام ڕێبەری شێوازی PEP 8 داوای یەک لە هەر دێڕێکدا دەکات، چونکە خوێندنەوەی ئاسانترە.
print("A") print("B") File "/Users/aram/python/two_on_one_line.py", line 1
print("A") print("B")
^^^^^
SyntaxError: invalid syntaxCapital letters and spaces matterپیتی گەورە و بۆشایی گرنگن
Python is : print, Print and PRINT are three different names, and only print is the function. Python 3.12 even suggests the right name:
Python : print، Print و PRINT سێ ناوی جیاوازن و تەنها print . Python 3.12 تەنانەت ناوە ڕاستەکە پێشنیار دەکات:
Print("Hello")Traceback (most recent call last):
File "/Users/aram/python/capital.py", line 1, in <module>
Print("Hello")
^^^^^
NameError: name 'Print' is not defined. Did you mean: 'print'?Spaces at the start of a line also mean something in Python. This is called . Later you will indent lines to group them under if, loops and functions (four spaces per level, as the style guide PEP 8 says; see Making decisions). Until then, start every line at the left edge. One extra space is enough to stop the program:
لە سەرەتای دێڕدا لە Pythonـدا واتای هەیە. پێی دەڵێن . دواتر دێڕەکان دەبەیتە ناوەوە بۆ ئەوەی لە ژێر if، و کۆیان بکەیتەوە (بۆ هەر ئاستێک چوار ، وەک ڕێبەری شێوازی PEP 8 دەڵێت؛ بڕوانە بڕیاردان). تا ئەو کاتە، هەموو دێڕێک لە لێواری چەپەوە دەست پێ بکە. تەنها زیادە بەسە بۆ وەستاندنی :
print("Line one")
print("Line two") File "/Users/aram/python/indent.py", line 2
print("Line two")
IndentationError: unexpected indentSpaces inside a line are free: print("Hi") and print( "Hi" ) do the same thing (PEP 8 prefers the first). Spaces inside quotes are part of the text and are printed.
لە ناو دێڕدا ئازادە: print("Hi") و print( "Hi" ) هەمان کار دەکەن (PEP 8 یەکەمیان پێ باشترە). لەناو بەشێکە لە دەقەکە و چاپ دەکرێت.
Comments: notes for peopleلێدوانەکان: تێبینی بۆ مرۆڤ
A note written for people to read. In code the computer ignores it: Python starts a comment with #; PHP, Java and C# use // for one line and /* … */ for several lines. On websites and social media, a comment is a short reply that a reader writes under a post or a video.
تێبینییەکە کە بۆ خوێندنەوەی خەڵک دەنووسرێت. لەناو کۆددا گوێی پێ نادات: Python لێدوان بە # دەست پێ دەکات؛ PHP، Java و C# بۆ یەک دێڕ // و بۆ چەند دێڕێک /* … */ بەکار دەهێنن. لە و تۆڕە کۆمەڵایەتییەکاندا، لێدوان وەڵامێکی کورتە کە خوێنەرێک لە ژێر پۆستێک یان ڤیدیۆیەکدا دەینووسێت.
A comment is a note in the program that explains the . Comments are for people: they document the program, remind you later of the tricky thing you did, and help the next person to read, understand and maintain your code. Python ignores them completely.
تێبینییەکە لەناو کە ڕوون دەکاتەوە. بۆ مرۆڤن: بەڵگەدار دەکەن، دواتر ئەو کارە ئاڵۆزەت بیر دەخەنەوە کە کردووتە و یارمەتیی کەسی دواتر دەدەن کۆدەکەت بخوێنێتەوە، لێی تێبگات و بیپارێزێت. Python بە تەواوی گوێیان پێ نادات.
In Python a comment starts with # and goes to the end of the line. It can fill a whole line, or follow the code on the same line. Putting # in front of a line of code “comments it out”: the line stays in the file but does not run, which is handy for testing.
لە Pythonـدا بە # دەست پێ دەکات و تا کۆتایی دێڕەکە دەڕوات. دەتوانێت هەموو دێڕێک پڕ بکاتەوە، یان لەسەر هەمان دێڕ بەدوای کۆدەکەدا بێت. دانانی # لە پێش دێڕێکی کۆد «دەیکاتە »: دێڕەکە لە فایلەکەدا دەمێنێتەوە بەڵام جێبەجێ ناکرێت، کە بۆ تاقیکردنەوە بەسوودە.
# Program: tea-house bill
# Prints the price of three glasses of tea.
print("Tea house bill") # the title
print("3 glasses of tea")
# print("This line is switched off, so it does not run.")
print("Total:", 3 * 500, "dinars")Tea house bill 3 glasses of tea Total: 1500 dinars
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
Whole-line comments describe the program.
کە هەموو دێڕێک دەگرن وەسف دەکەن.
- Lineدێڕی 4
A comment after the code, separated by at least two spaces.
دوای کۆدەکە، کە بە لانیکەم دوو جیا کراوەتەوە.
- Lineدێڕی 6
A line of code that has been commented out: it does not run.
دێڕێکی کۆد کە کراوەتە : جێبەجێ ناکرێت.
Why programs need comments and how to write a comment with #, shown in real code.
بۆچی پێویستیان بە هەیە و چۆن بە # دەنووسیت، لەناو کۆدی ڕاستەقینەدا.
Watch 0:11-2:37: why comments, and # comments. It stops before 2:37, where the video calls triple quotes a multi-line comment (the lesson explains they are strings).
لە 0:11 تا 2:37 سەیر بکە: بۆچی پێویستە و #. پێش 2:37 ڕادەوەستێت، چونکە لەوێدا ڤیدیۆکە """ بە چەند دێڕی ناو دەبات (وانەکە ڕوونی دەکاتەوە کە ئەمە ).
Comments: notes for peopleلێدوانەکان: تێبینی بۆ مرۆڤ
Comments never runلێدوانەکان هەرگیز جێبەجێ ناکرێن
When Python reads your file, it removes every comment before the program runs. So a comment can never change what the program does.
کاتێک Python فایلەکەت دەخوێنێتەوە، پێش جێبەجێکردنی هەموو لادەبات. بۆیە هەرگیز ناتوانێت ئەوە بگۆڕێت کە دەیکات.
A # inside quotation marks is just a character of the text, not the start of a comment: print("Room #12") prints Room #12.
# لەناو تەنها دەقەکەیە، نەک سەرەتای : print("Room #12") دەنووسێت Room #12.
| Languageزمان | One lineیەک دێڕ | Several linesچەند دێڕێک |
|---|---|---|
| Python | # comment | # on every line# لە هەموو دێڕێکدا |
| Java, C#, JavaScript | // comment | /* comment */ |
| PHP | // or #// یان # | /* comment */ |
| HTML | <!-- comment --> | <!-- comment --> |
Python and Java side by side are compared in Python next to Java.
Python و Java لە تەنیشت یەکەوە لە Python لە تەنیشت Java بەراورد کراون.
Comments: notes for peopleلێدوانەکان: تێبینی بۆ مرۆڤ
Longer comments and triple quotesلێدوانی درێژتر و سێ نیشانەی گوتە
Python has no special sign for a comment that covers several lines. You simply start each line with #. Editors can do it for you: in IDLE choose Format › Comment Out Region (Alt+3), in VS Code press Ctrl+/ (Cmd+/ on a Mac).
Python هیچ نیشانەیەکی تایبەتی نییە بۆ کە چەند دێڕێک بگرێتەوە. بە سادەیی هەر دێڕێک بە # دەست پێ دەکەیت. دەستکاریکەرەکان دەتوانن ئەمە بۆت بکەن: لە IDLE Format › Comment Out Region (Alt+3) هەڵبژێرە، لە VS Code Ctrl+/ دابگرە (لەسەر Mac Cmd+/).
# This program prints a short timetable.
# It was written for the first Python lesson.
# Change the times when the timetable changes.
print("08:30 Programming")
print("10:30 Mathematics")08:30 Programming 10:30 Mathematics
You will often see text between three quotation marks, """…""", used like a long comment. It is not a comment. It is a string that can cover several lines. If it stands alone, Python creates it and throws it away, so it seems to do nothing. If you print it, you see it:
زۆرجار دەقێک دەبینیت لە نێوان سێ ، """…"""، کە وەک درێژ بەکار دێت. ئەمە نییە. کە دەتوانێت چەند دێڕێک بگرێتەوە. ئەگەر بە تەنها بوەستێت، Python دروستی دەکات و فڕێی دەدات، بۆیە وا دەردەکەوێت هیچ ناکات. ئەگەر چاپی بکەیت، دەیبینیت:
"""
This text is a string, not a comment.
Python creates it and then throws it away.
"""
print("Only this line prints.")
print("""A triple-quoted string
can go over
several lines.""")Only this line prints. A triple-quoted string can go over several lines.
A triple-quoted string has one special job. Written as the first line of a , a class or a file, it becomes a : Python keeps it, and help() shows it to anyone who uses your code. You will write docstrings in Defining and calling functions.
بە سێ کارێکی تایبەتی هەیە. ئەگەر وەک یەکەم دێڕی ، یان فایلێک بنووسرێت، دەبێتە : Python هەڵیدەگرێت و help() پیشانی هەر کەسێک دەدات کە کۆدەکەت بەکار دەهێنێت. لە ناساندن و بانگکردنی کردارەکان دەنووسیت.
Comments: notes for peopleلێدوانەکان: تێبینی بۆ مرۆڤ
Writing good commentsنووسینی لێدوانی باش
- Say why, not what. The code already says what it does; a comment should add what the code cannot say, such as the meaning of a number or the reason for a choice.
- Keep comments up to date. When you change the code, change the comment. PEP 8 warns that a comment that disagrees with the code is worse than no comment.
- Format them neatly. Write
#with one space after#, and leave at least two spaces before a comment at the end of a line.
- بڵێ بۆچی، نەک چی. کۆدەکە خۆی دەڵێت چی دەکات؛ دەبێت ئەوە زیاد بکات کە کۆدەکە ناتوانێت بیڵێت، وەک واتای ژمارەیەک یان هۆکاری هەڵبژاردنێک.
- نوێ ڕابگرە. کاتێک کۆدەکە دەگۆڕیت، بگۆڕە. PEP 8 ئاگادار دەکاتەوە کە کە لەگەڵ کۆدەکەدا ناکۆک بێت لە نەبوونی خراپترە.
- بە ڕێکی بیاننووسە.
#بە یەک دوای#بنووسە و لانیکەم دوو پێش ئەو لە کۆتایی دێڕدایە دابنێ.
# Weak: the comment only repeats the code.
print(3 * 500) # print 3 times 500
# Better: the comment says what the numbers mean.
print(3 * 500) # 3 glasses of tea at 500 dinars each1500 1500
Comments: notes for peopleلێدوانەکان: تێبینی بۆ مرۆڤ
A checklist for readable programsلیستی پشکنینی بەرنامەی خوێنراو
Comments are one part of documentation: everything that helps a person understand your program. Before you hand in a program, check it against this list:
بەشێکن لە : هەموو ئەو شتانەی یارمەتیی مرۆڤ دەدەن لە تێبگات. پێش ئەوەی ڕادەست بکەیت، بە پێی ئەم لیستە بیپشکنە:
- Purpose at the top: a comment on the first lines says what the program does. Later, every function says what it does too: see docstrings.
- Useful comments, not too many: explain why, not what every line already says.
- Meaningful names:
priceandtotal_marks, notxandt(one-letter names only for short counters): see Choosing good names. - One naming style everywhere: in Python, for variables and functions.
- Meaningful file names:
tea_bill.py, nottest1.pyornew.py. - Correct, even indentation: 4 spaces for each level.
- ئامانج لە سەرەوە: لە یەکەم دێڕەکاندا دەڵێت چی دەکات. دواتر هەموو دەڵێت چی دەکات: بڕوانە زنجیرەنووسەی بەڵگەنامە.
- بەسوود، نەک زۆر: بۆچی ڕوون بکەرەوە، نەک ئەوەی هەموو دێڕێک خۆی دەیڵێت.
- ناوی واتادار:
priceوtotal_marks، نەکxوt(ناوی یەک پیتی تەنها بۆ کورت): بڕوانە هەڵبژاردنی ناوی باش. - یەک شێوازی ناونان لە هەموو شوێنێک: لە Pythonـدا بۆ و .
- ناوی واتادار بۆ :
tea_bill.py، نەکtest1.pyیانnew.py. - دروست و ڕێک: 4 بۆ هەر ئاستێک.
Common mistakesهەڵە باوەکان
Every message below is the real output of Python 3.12. Newer versions word a few of them a little differently.
هەموو پەیامێکی خوارەوە ڕاستەقینەی Python 3.12ـە. وەشانە نوێترەکان هەندێکیان کەمێک جیاواز دەنووسن.
| Mistakeهەڵە | Python saysPython دەڵێت | Fixچارەسەر |
|---|---|---|
print(“Hi”) | SyntaxError: invalid character '“' (U+201C) | Retype straight quotes "Hi". "Hi" بنووسەرەوە. |
print("Hi) | SyntaxError: unterminated string literal (detected at line 1) | Close the string with the same kind of quote. بە هەمان جۆری دابخە. |
print("Hi') | SyntaxError: unterminated string literal (detected at line 1) | Use the same quote at both ends.لە هەردوو سەرەوە هەمان بەکار بهێنە. |
print("Hi" | SyntaxError: '(' was never closed | Add the closing ).)ـی داخستن زیاد بکە. |
Print("Hi") | NameError: name 'Print' is not defined. Did you mean: 'print'? | Write print in small letters.print بە پیتی بچووک بنووسە. |
print "Hi" | SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? | This is Python 2 style; write print("Hi").ئەمە شێوازی Python 2ـیە؛ بنووسە print("Hi"). |
A space before print on a new line پێش print لە دێڕێکی نوێدا | IndentationError: unexpected indent | Start the line at the left edge.دێڕەکە لە لێواری چەپەوە دەست پێ بکە. |
print(Hello) | NameError: name 'Hello' is not defined | Text needs quotes: print("Hello").دەق پێویستە: print("Hello"). |
print("A") print("B") | SyntaxError: invalid syntax | One statement per line.لە هەر دێڕێکدا یەک . |
Errors and debugging shows how to read these messages calmly: last line first.
هەڵەکان و کرمەکوژی پیشان دەدات چۆن بە هێمنی ئەم پەیامانە بخوێنیتەوە: سەرەتا دوایین دێڕ.
Practiceڕاهێنان
Write a program card.py that starts with a comment saying what it does and prints three lines: a name, a city and a favourite food. Use a made-up person if you like.
بە ناوی card.py بنووسە کە بە دەست پێ بکات کە دەڵێت چی دەکات و سێ دێڕ چاپ بکات: ناوێک، شارێک و خواردنێکی دڵخواز. ئەگەر حەز دەکەیت کەسێکی دەستکرد بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
# My name card
print("Name: Dilan")
print("City: Erbil")
print("Favourite food:", "dolma")Name: Dilan City: Erbil Favourite food: dolma
This program has four mistakes. Python shows them one at a time. Run it, fix the error it reports, and run it again until it works.
ئەم بەرنامەیە چوار هەڵەی تێدایە. Python هەر جارە یەکێکیان پیشان دەدات. جێبەجێی بکە، ئەو هەڵەیەی ڕای دەگەیەنێت چاکی بکە و دووبارە جێبەجێی بکەرەوە تا کار دەکات.
Print("Welcome to Python!")
print("Python is case-sensitive.)
print(“Use straight quotes:”, "like these")Hintئاماژە
Python first reports the syntax errors (lines 2 and 3). The capital P on line 1 is found only when the program finally runs.
Python سەرەتا ڕادەگەیەنێت (دێڕەکانی 2 و 3). Pـی گەورە لە دێڕی 1 تەنها کاتێک دەدۆزرێتەوە کە لە کۆتاییدا جێبەجێ دەبێت.
Show answerوەڵامەکە پیشان بدە
Run 1:
SyntaxError: unterminated string literal (detected at line 2). Add the closing"on line 2.جێبەجێکردنی 1:
SyntaxError: unterminated string literal (detected at line 2)."ـی داخستن لە دێڕی 2 زیاد بکە.Run 2:
IndentationError: unexpected indenton line 3. Remove the two spaces at its start.جێبەجێکردنی 2:
IndentationError: unexpected indentلە دێڕی 3. هەردوو سەرەتای دێڕەکە لاببە.Run 3:
SyntaxError: invalid character '“' (U+201C)on line 3. Retype the curly quotes as straight quotes.جێبەجێکردنی 3:
SyntaxError: invalid character '“' (U+201C)لە دێڕی 3. بە بنووسەرەوە.Run 4:
NameError: name 'Print' is not defined. Did you mean: 'print'?on line 1. Writeprint.جێبەجێکردنی 4:
NameError: name 'Print' is not defined. Did you mean: 'print'?لە دێڕی 1. بنووسەprint.
print("Welcome to Python!")
print("Python is case-sensitive.")
print("Use straight quotes:", "like these")Welcome to Python! Python is case-sensitive. Use straight quotes: like these
Without running it, write down exactly what this program prints. Then run it and compare.
بەبێ جێبەجێکردن، بە وردی بنووسە ئەم بەرنامەیە چی چاپ دەکات. پاشان جێبەجێی بکە و بەراوردی بکە.
# print("A")
print("B", "C") # print("D")
print()
print("E", 5, "F")Show answerوەڵامەکە پیشان بدە
Line 1 and the end of line 2 are comments. Line 3 prints an empty line. Commas become single spaces:
دێڕی 1 و کۆتایی دێڕی 2 . دێڕی 3 دێڕێکی بەتاڵ چاپ دەکات. کۆماکان دەبن بە یەک :
B C E 5 F
Add a two-line comment at the top that explains the program, and one end-of-line comment that says why 20 cups are needed. The output must not change.
دوو دێڕی لە سەرەوە زیاد بکە کە ڕوون بکاتەوە و کۆتایی دێڕ کە بڵێت بۆچی 20 کوپ پێویستە. نابێت بگۆڕێت.
print("Tea")
print("Sugar")
print("Cups")Show answerوەڵامەکە پیشان بدە
# Shopping list for the tea house.
# Prints each item on its own line.
print("Tea")
print("Sugar")
print("Cups") # we need 20 new cupsTea Sugar Cups
Summaryپوختە
print()is a built-in function: it writes its arguments to the screen (standard output), turning numbers and other values into text first.- Text (a string) goes between matching straight quotes,
"…"or'…'. Curly quotes cause a SyntaxError. - Commas separate several values;
print()puts one space between them and ends the line. - One statement per line, run from top to bottom; the whole file is checked for syntax errors first.
- Python is case-sensitive, and spaces at the start of a line (indentation) have meaning.
#starts a comment that runs to the end of the line. Triple-quoted text is a string (a docstring when it is the first line of a function), not a comment.
print(): دەنووسێت بۆ سەر شاشە ( ستاندارد) و سەرەتا ژمارە و تر دەگۆڕێت بۆ دەق.- دەق () دەچێتە نێوان وەک یەک،
"…"یان'…'. SyntaxError دروست دەکات. - کۆما چەند لێک جیا دەکاتەوە؛
print()یەک دەخاتە نێوانیانەوە و دێڕەکە کۆتایی پێ دەهێنێت. - لە هەر دێڕێکدا یەک ، لە سەرەوە بۆ خوارەوە جێبەجێ دەکرێن؛ سەرەتا هەموو فایلەکە بۆ دەپشکنرێت.
- Python و لە سەرەتای دێڕدا () واتای هەیە.
#دەست پێ دەکات کە تا کۆتایی دێڕەکە دەڕوات. دەقی ناو سێ (کاتێک یەکەم دێڕی بێت )، نەک .
Why does print(Hello) give a NameError?بۆچی print(Hello) NameError دەدات؟
Without quotes, Hello is read as a name, and nothing is called Hello.
بەبێ ، Hello وەک ناو دەخوێندرێتەوە و هیچ شتێک ناوی Hello نییە.
What does an empty print() do?print()ـی بەتاڵ چی دەکات؟
It prints an empty line.
دێڕێکی بەتاڵ چاپ دەکات.
Is """text""" a comment?ئایا """text""" لێدوانە؟
No. It is a string. Python creates it; as the first line of a function it becomes a docstring. Only # starts a comment.
نەخێر. . Python دروستی دەکات؛ وەک یەکەم دێڕی دەبێتە . تەنها # دەست پێ دەکات.
Why did nothing print when one line of your file had a missing quote?بۆچی هیچ چاپ نەکرا کاتێک لە یەک دێڕی فایلەکەتدا نیشانەیەکی گوتە نەبوو؟
Python checks the whole file before running it; a syntax error anywhere stops everything.
Python پێش جێبەجێکردن هەموو فایلەکە دەپشکنێت؛ لە هەر شوێنێک بێت هەموو شتێک دەوەستێنێت.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
David Malan writes hello, world with print(), explains functions and arguments, and fixes a first bug.
David Malan بە print() دەنووسێت hello, world، و ڕوون دەکاتەوە و یەکەم چاک دەکات.
Watch 4:45-14:40 ('Your First Program').
لە 4:45 تا 14:40 سەیر بکە (Your First Program).
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Errors and Debuggingهەڵەکان و کرمەکوژی
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Python tutorial 3.1.2: Text (strings and print)
- Python documentation: built-in function print()
- Python language reference 2: Lexical analysis (comments, indentation, identifiers)
- Python tutorial 2.2.1: Source code encoding (UTF-8)
- PEP 8: Style Guide for Python Code (comments, indentation, one statement per line)
- Python documentation: IDLE (Format menu, Comment Out Region)
- Harvard CS50P, lecture 0 notes (functions, bugs, comments)
- Liang, Introduction to Programming Using Python: table of contents (chapters 1–2)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.