Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
learn-python/src/data_types/test_numbers.py at master · ve59/learn-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ve59
learn-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
learn-python
/
src
/
data_types
/
test_numbers.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
120 lines (86 loc) · 3.25 KB
master
Breadcrumbs
learn-python
/
src
/
data_types
/
test_numbers.py
Copy path
Top
File metadata and controls
Code
Blame
120 lines (86 loc) · 3.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Numbers.
@see: https://docs.python.org/3/tutorial/introduction.html
@see: https://www.w3schools.com/python/python_numbers.asp
There are three numeric types in Python:
- int (e.g. 2, 4, 20)
- bool (e.g. False and True, acting like 0 and 1)
- float (e.g. 5.0, 1.6)
- complex (e.g. 5+6j, 4-3j)
"""
def
test_integer_numbers
():
"""Integer type
Int, or integer, is a whole number, positive or negative,
without decimals, of unlimited length.
"""
positive_integer
=
1
negative_integer
=
-
3255522
big_integer
=
35656222554887711
assert
isinstance
(
positive_integer
,
int
)
assert
isinstance
(
negative_integer
,
int
)
assert
isinstance
(
big_integer
,
int
)
def
test_booleans
():
"""Boolean
Booleans represent the truth values False and True. The two objects representing the values
False and True are the only Boolean objects. The Boolean type is a subtype of the integer type,
and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the
exception being that when converted to a string, the strings "False" or "True" are returned,
respectively.
"""
true_boolean
=
True
false_boolean
=
False
assert
true_boolean
assert
not
false_boolean
assert
isinstance
(
true_boolean
,
bool
)
assert
isinstance
(
false_boolean
,
bool
)
# Let's try to cast boolean to string.
assert
str
(
true_boolean
)
==
"True"
assert
str
(
false_boolean
)
==
"False"
def
test_float_numbers
():
"""Float type
Float, or "floating point number" is a number, positive or negative,
containing one or more decimals.
"""
float_number
=
7.0
# Another way of declaring float is using float() function.
float_number_via_function
=
float
(
7
)
float_negative
=
-
35.59
assert
float_number
==
float_number_via_function
assert
isinstance
(
float_number
,
float
)
assert
isinstance
(
float_number_via_function
,
float
)
assert
isinstance
(
float_negative
,
float
)
# Float can also be scientific numbers with an "e" to indicate
# the power of 10.
float_with_small_e
=
35e3
float_with_big_e
=
12E4
assert
float_with_small_e
==
35000
assert
float_with_big_e
==
120000
assert
isinstance
(
12E4
,
float
)
assert
isinstance
(
-
87.7e100
,
float
)
def
test_complex_numbers
():
"""Complex Type"""
complex_number_1
=
5
+
6j
complex_number_2
=
3
-
2j
assert
isinstance
(
complex_number_1
,
complex
)
assert
isinstance
(
complex_number_2
,
complex
)
assert
complex_number_1
*
complex_number_2
==
27
+
8j
def
test_number_operators
():
"""Basic operations"""
# Addition.
assert
2
+
4
==
6
# Multiplication.
assert
2
*
4
==
8
# Division always returns a floating point number.
assert
12
/
3
==
4.0
assert
12
/
5
==
2.4
assert
17
/
3
==
5.666666666666667
# Modulo operator returns the remainder of the division.
assert
12
%
3
==
0
assert
13
%
3
==
1
# Floor division discards the fractional part.
assert
17
//
3
==
5
# Raising the number to specific power.
assert
5
**
2
==
25
# 5 squared
assert
2
**
7
==
128
# 2 to the power of 7
# There is full support for floating point; operators with
# mixed type operands convert the integer operand to floating point.
assert
4
*
3.75
-
1
==
14.0
You can’t perform that action at this time.