0% found this document useful (0 votes)
17 views26 pages

Slot3 InOut

The document discusses input and output in Python programming. It covers topics like data types, variables, literals, operators, and functions like print() and input() for displaying and getting data from the user.

Uploaded by

levohonghuy2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views26 pages

Slot3 InOut

The document discusses input and output in Python programming. It covers topics like data types, variables, literals, operators, and functions like print() and input() for displaying and getting data from the user.

Uploaded by

levohonghuy2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Department of Computing Fundamentals

PFP191 – Programming Fundamentals with Python

Slot 03 -
Input/Output
Presenter:
Dr. LE Thanh Tung

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 1


Content

1 Data Types
2 Input/ Output
3 Expression
4 Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 2


Data Types

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 3


Variables
▪ Variables are containers for storing data values
▪ Creating variable:
▪ Python has no command for declaring a variable.
▪ A variable is created the moment you first assign a value to it.

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 4


Variables
▪ Rules for Naming Python Variables:
▪ Python is case-sensitive (i.e: num  Num)
▪ Contains Alphabet (upper/lowercase), Digits (0-9), underscore (_)
▪ First letter: Alphabet, underscore
▪ Avoid Keywords

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 5


Casting
▪ If you want to specify the data type of a variable, this can be
done with casting

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 6


Constant
▪ A constant is a special type of variable whose value cannot be changed
▪ In Python, constants are usually declared and assigned in a module (a
new file containing variables, functions, etc which is imported to the main
file)
▪ Note: In reality, we don't use constants in Python. Naming them in all capital
letters is a convention to separate them from variables, however, it does not
actually prevent reassignment.

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 7


Literals
▪ Literals are representations of fixed values in a program
▪ Numeric Literals are immutable (unchangeable). Numeric literals can
belong to 3 different numerical types: Integer, Float, and Complex.

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 8


Assign Operator
▪ Assign operator “=“: put the value from right-hand side to left-hand side

▪ Assigning multiple values to multiple variables

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 9


Does it work?
▪ What is the value of site1, site2 ?

▪ Separate it into the simple process?

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 10


Input/Output
▪ Output: display the data to users (Console/File)

print(<value>):

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 11


print()

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 12


print()

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 13


print()

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 14


print()

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 15


print()

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 16


Input/Output
▪ Output: display the data to users (Console/File)

print(<value>):

▪ Input: get the data from users (Console/File)

input([prompt])

▪ However, all input value is string


LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 17
Expression
▪ Expression: is the combination of operands and operatos

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 18


Operators
▪ Arithmetic Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 19


Operators
▪ Relational Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 20


Operators
▪ Assignment Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 21


Operators
▪ Logical Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 22


Operators
▪ Membership Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 23


Operators
▪ Identity Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 24


Operators
▪ Bitwise Operators

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 25


THANK YOU
for YOUR ATTENTION

LE, Thanh Tung PFP191-Programming Fundamentals with Python Page 26

You might also like