Skip to content

Latest commit

 

History

History
executable file
·
110 lines (78 loc) · 1.2 KB

File metadata and controls

executable file
·
110 lines (78 loc) · 1.2 KB

Operators

Examples in Python 3

Numeric values

"""
Addition
"""
x = 40 + 2
print(x)

"""
Subtraction
"""
x = 8 - 50
print(x)

"""
Multiplication
"""
x = 6 * 7
print(x)

x = 5.6 * 7.5
print(x)

"""
Division
"""
x = 126 / 3
print(x)        # float

x = 126 // 3    # integer
print(x)

x = 71.4 / 1.7
print(x)

x = 71.4 // 1.7
print(x)

"""
Powers
"""
x = 5**2
print(x)

x = 2**10
print(x)

x = 6.49**2
print(x)

"""
Modulus
"""
x = 242 % 50
print(x)

Strings

"""
Concatenation
"""
x = "Hello" + "World"
print(x)

x = "Hello"
y = "World"
print(x + " " + y)
print(x, y)

x = "4"
y = "2"
print(x + y)
print(x, y)

"""
Multiplication
"""
x = "Na" * 10
print(x + " Watman!")

Reference and read more

Operators

Mapping Operators to Functions

Numbers

Strings

Revision history

2014-07-16 (sylvanas) PA1 First try.