chapter 3 fundamental concepts

12 0 0
Tài liệu đã được kiểm tra trùng lặp
chapter 3 fundamental concepts

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TALENTS FOR DEVELOPMENT - Petrovietnam UniversityChapter 3: Fundamental conceptsLecturer: Tran Ngoc Hiep, MSc.Email: hieptn@pvu.edu.vnMobile: 0901 252468ContentsStructure of Python prog

Trang 1

TALENTS FOR DEVELOPMENT - Petrovietnam University

Chapter 3: Fundamental concepts

Lecturer: Tran Ngoc Hiep, MSc.Email: hieptn@pvu.edu.vnMobile: 0901 252468

ContentsStructure of

Python programBasic conceptsVariables

Python Basic Data

TypesInput – Output in Python1

Trang 2

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

Sample program

3.1 Structure of Python program3

Trang 3

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.2 Basic concept

In Python, each individual statement must be ended with “enter”

Semicolons:

3.2 Basic conceptBlock in Python:

Python uses indentationto indicate a block of code.

All the statements inside the block is treated as one unit Blocks are used as the body in constructs like function, if-else and loop, which may contain multiple statements but are treated as one unit.5

Trang 4

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.2 Basic conceptComments:

Program comments are explanatory statements that you can include in Python code and helps anyone easier to read and understand.

Python support single-line and multi-line comments

Single Line Comment Multi Line Comment

3.2 Basic conceptKeyword:

7

Trang 5

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

9

Trang 6

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.3 VariablesVariable naming:

We can naming the variables by using:

Upper case letter

Lower case letter

Trang 7

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.3 VariablesVariable Declaration:

Take note:

In Python, you don’t need to declare the name of variable

before it can be used.

Python is not a “Strongly-type” language.

3.3 Variables

Declaration and Initialization of Variable

Python has no command for declaring a variable.

A variable is createdthe moment you first assign a value to it.

Example:13

Trang 8

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.3 Variables

Declaration and Initialization of Variable:

Initialization means assigning value to an already declared variable.

Initialization and declaration can be done in single step also.

3.4 Python Basic Data Types15

Trang 9

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.4 Python Basic Data Types

3.5 Input - Output in Python

To input and output data in Python we use input() and print()methods.

print- object providing a connection to the monitorinput- object providing a connection to the keyboard17

Trang 10

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

3.5 Input - Output in Python

Summary

1• Structure of Python program

2• Basic concept: Identity, keyword, comment…3• Declaring and using variable

4• Basic datatype in Python5• Input/output in Python19

Trang 11

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University

Discussion21

Trang 12

Tran Ngoc Hiep, MSc Foundations of Engineering II- PVU

TALENTS FOR DEVELOPMENT - Petrovietnam University 23

23

Ngày đăng: 17/06/2024, 15:00