Term 1 | Term 2 | Term 3 | Term 4 |
Unit 11.1А: Python programming Basics
| Unit 11.2A: 11.2А Data structures in Python
| Unit 11.3А: Data structures in Python (continuation)
| Unit 11.4A: 11.4A Object-oriented programming
|
INTRODUCTION TO THE PYTHON PROGRAMMING LANGUAGE�OUTPUT OF DATA
11.1А PYTHON PROGRAMMING BASICS
Learning objectives:
11.1.1.1 arrange data output;
11.1.1.2 use escape sequences in data output;
Expected outcomes
Video overview of the �Python programming language
What is Python?�
Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.
It is used for:
- web development (server-side),
- software development,
- mathematics,
- system scripting.
What can Python do?
Why Python?
Python Syntax compared to other programming languages
Python was designed for readability, and has some similarities to the English language with influence from mathematics.
Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
Comparison
Determine what happens when outputting the next line
Consider a program to greet the user in various programming languages
С++ | Python |
#include <iostream> using namespace std; int main() { string username; cout << "What is your name? \n"; cin >> username; cout << "Hello, " << username << "!"; } | print(‘What is your name?’) username = input() print(‘Hello, ’, username, ‘!’) |
Discussion 5 min
Discuss the advantages and disadvantages of Python and list them below.
Online python interpreter
Output
For standard output, Python uses the print command.
Note that you can use either double quotes or apostrophes when outputting strings.
Example:
print("Hello, world!") # correct
print('Hello, world!') # correct
print("Hello, world!') # incorrect
The “sep” and “end” parameters
print("text1", "text2", "text3") # output has three arguments.
Result:
text1 text2 text3
Use of sep parameter (separator – разделитель)
print("text1", "text2", "text3", sep="---")
Result:
text1---text2---text3
Use of end parameter
print("text1", end=" ")
print("text2", end=" ")
print("text3")
Результат:
text1 text2 text3
Python Comments
Comments starts with a #, and Python will ignore them:
Python Escape Characters
To insert characters that are illegal in a string, use an escape character.
An escape character is a backslash \ followed by the character you want to insert.
An example of an illegal character is a double quote inside a string that is surrounded by double quotes:
To fix this problem, use the escape character \":
Other escape characters used in Python:
Code | Result |
\' | Single Quote |
\\ | Backslash |
\n | New Line |
\r | Carriage Return |
\t | Tab |
Examples
print("text1\ntext2")
result:
text1
text2
print(“Carrot\t150 tenge\nPotato\t180 tenge")
result:
Carrot 150 tenge
Potato 180 tenge
Determine what happens when outputting the next lines:
print('line 1\nline 2\nline 3')
print('This is a backslash: \\')
print('Don\t worry be happy!’)
print(5 + 3)
print(11 – 7)
print(‘10 * 5’)
Write a Python program to print the following string in a specific format
15:00 movie "Avengers"
16:30 show "The Tonight Show Starring Jimmy Fallon"
Tasks
https://stepik.org/lesson/449955/step/1?unit=440339
Reflection