1 of 22

Term 1

Term 2

Term 3

Term 4

Unit 11.1А: Python programming Basics

  • Introduction to the python programming language. Input and output of data
  • Programmimg of branching algorithms
  • Programming of loops

Unit 11.2A: 11.2А Data structures in Python

  • Data structures: Sets
  • Data structures: Strings

Unit 11.3А: Data structures in Python (continuation)

  • Data structures: Lists and Tuples
  • Data structures: Nested lists
  • Data structures: Dictionaries

Unit 11.4A: 11.4A Object-oriented programming

  • Object-oriented programming: User-defined functions
  • Object-oriented programming: Classes
  • Object-oriented programming: Tkinter

2 of 22

INTRODUCTION TO THE PYTHON PROGRAMMING LANGUAGE�OUTPUT OF DATA

11.1А PYTHON PROGRAMMING BASICS

3 of 22

Learning objectives:

11.1.1.1 arrange data output;

11.1.1.2 use escape sequences in data output;

4 of 22

Expected outcomes

  • Students will:
    • organize data output;
    • use escape sequences when outputting data;
    • explain the difference in writing basic Python statements with other programming languages previously learned.

​

5 of 22

Video overview of the �Python programming language

​

6 of 22

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.

​

7 of 22

What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

​

8 of 22

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-oriented way or a functional way.

​

9 of 22

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.

10 of 22

Comparison

Determine what happens when outputting the next line

Consider a program to greet the user in various programming languages

​

​

​

​

​

​

​

​

​

  • Which programming language is easier to understand?
  • What language will be written faster than others?

​

​

​

С++

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, ‘!’)

11 of 22

Discussion 5 min

Discuss the advantages and disadvantages of Python and list them below.

12 of 22

Online python interpreter

​

13 of 22

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

14 of 22

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

​

​

15 of 22

Python Comments

Comments starts with a #, and Python will ignore them:

​

16 of 22

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 \":

​

​

17 of 22

Other escape characters used in Python:

Code

Result

\'

Single Quote

\\

Backslash

\n

New Line

\r

Carriage Return

\t

Tab

18 of 22

Examples

print("text1\ntext2")

result:

text1

text2

print(“Carrot\t150 tenge\nPotato\t180 tenge")

result:

Carrot 150 tenge

Potato 180 tenge

19 of 22

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’)

20 of 22

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"

​

21 of 22

Tasks

https://stepik.org/lesson/449955/step/1?unit=440339

22 of 22

Reflection