Your First Python Program
Python is an easy-to-learn and widely used programming language. We learn to print text, read input from the user and write comments, and then write our first program.
All topics (1 of 11)
Chapter 1. Python Basics
Chapter 2. Lists and Strings
Chapter 3. Functions and Modules
Chapter 4. Working with Files
Python is an easy-to-learn and widely used programming language. It was created by Guido van Rossum, and its first version appeared in 1991. Today Python is used to build websites, analyze data, create artificial intelligence and automate tasks.
To write programs you need a Python interpreter and a text editor. For beginners, IDLE, which is usually installed together with Python, or Thonny is convenient. The interpreter carries out the commands of the program one after another, from top to bottom.
The very first program prints text on the screen: print("Salom, dunyo!"). Here print is the output function, and the text in quotation marks inside the parentheses is called a string. When the program runs, the words Salom, dunyo! (“Hello, world!” in Uzbek) appear on the screen, and the quotation marks are not shown.
To get data from the user, the input() function is used: name = input("Ismingiz nima? "). The entered name can be printed with the command print("Salom,", name). Python distinguishes uppercase and lowercase letters, so writing Print causes an error. Text after the # sign is a comment and does not affect how the program works: # Greeting program.
Key takeaways
- Python is an easy-to-learn and widely used programming language.
- The
print()function outputs data to the screen, andinput()gets data from the user. - Text (a string) is written in quotation marks.
- Python distinguishes uppercase and lowercase letters.
- A comment starts with the
#sign and is not executed.
Practice tasks
- Open a Python environment (IDLE or Thonny), type in and run the program
print("Salom, dunyo!"); then changeprinttoPrintand see what message appears. - Write a program that prints your name and your class on two lines; use two
print()commands. - Use
input()to ask the user for a name and greet them by name; write a comment at the beginning of the program.
Review questions
Test yourself: think first, then reveal the answer.
1What does the print() function do?Show answerHide answer
It outputs text or other data to the screen.2Which sign is used to write a comment in Python?Show answerHide answer
The hash sign (#); a comment does not affect how the program runs.3Why does the command Print("Salom") cause an error?Show answerHide answer
Python distinguishes uppercase and lowercase letters, and there is no function called Print.
0 of 11 topics completed
Sign in to mark