Exploring Smartphone Influence on the Brain: Neurological Perspectives
Angular vs. React: Which One Should You Choose?
Discover Serenity: Your Guide to Mindfulness Apps
Discover how smartphone apps can enhance your mindfulness practice: 5 Senses Exercise with Apps
Discover How Smartwatches Measure Blood Pressure: Explained Simply
13 Exciting Games Launching in April 2024: From Freedom Planet 2 to TopSpin 2K25!
Discover the 5 Amazon Big Spring Deals on Tablets from Samsung, Lenovo
Big Savings Alert: Amazfit Smart Watches Now on Sale on Amazon!
Amazon's Big Spring Sale: Top 6 Anker Souncore Headphones and Earbuds Deals
Affordable VR Adventures: The Best Budget VR Headsets
Fly in Peace: Discover the Ultimate Noise-Cancelling Headphones for Flying
Bringing AI to Life: NVIDIA's Digital Human Technolgies in Healthcare, Gaming, and More
Discover Exciting New Games on NVIDIA GeForce NOW!
Steam Spring Sale 2024 is here: Explore the 10 Best FPS Games
The Future of iPhones: Apple's Bold Step into AI with DarwinAI
Discover the Magic of Sonos Soundbar: Transform Your Home Entertainment Experience!
Enhance Your Home Fun: 5 Best Sonos Soundbars to Amp Up Your Entertainment!
Pinterest Introduces AI-Powered Body Type Ranges for Inclusive Searches
Embrace the Next Wave: 35+ AI Tools for Enhanced Productivity in 2024
Xbox Gaming Bonanza: Lots of New Games with Xbox Game Pass!
Sony Paves the Way for Gaming Evolution with 'Super-Fungible Tokens' Patent
Smart Printing Choices: 10 Key Factors to Consider When Buying an HP Printer or Any Printer
Projector Picks: Explore the Best Mini Projectors for Big Screen Fun!
JavaScript Essentials: Your Quick Start to Web Coding
Gaming Laptop Guide 2024: 10 Crucial Checks Before You Buy + Top 5 Picks for you!
Gaming Joy Awaits: Explore the Best PS5 Games of 2024
Epic Games Special: Dive into Astro Duel 2 for FREE this week. See What’s Coming Next Week!
Fitbit Fitness Tracker Guide 2024: Choose Your Perfect Fit
Feel the Beat: Exploring Top Over-Ear Headphones
Explore the Web Development Strategies in 2024: A Developers Handbook
Explore Must-Play Nintendo Switch Games in 2024!
Eclipse Ready: CE and ISO Certified Solar Eclipse Glasses for a Safe Sky Spectacle
Disney and Pixar’s Inside Out 2 Introduces New Emotions to Riley's World
Discover Waze's cool new features for safer and happier drives!
Discover the Top Picks: Best Smartwatches for Your Lifestyle
Discover the Best Smartphones Trending Now: Your Easy Guide to the Best Picks!
Sound Revolution: Discover the Best Bluetooth Speakers of 2024!
Discover the 10 Best Productivity Apps to Supercharge Your Daily Tasks
Discover,Install and Enjoy: The Best Chrome Extensions for Developers in 2024
Crack the Code: Your Guide to Computer Programming Magic in 2024
Boost Your Content Creation: 10 ChatGPT Prompts to Supercharge Content Creation Productivity
10 Best Tech Companies in Silicon Valley
Top 10 Web Development Interview Questions you can...
Learn how to Answer Tell me about Yourself
5 Books You Need to Read Right Now
25 Practical Ways to Earn Money Online
Translate this page in your preferred language:
Article by: Manish Methani
Last Updated: October 7, 2021 at 8:04am IST
Here are some examples:
# Integers x = 5 y = -10 z = 0 # Floating-point numbers a = 3.14 b = 1.23e-5 # Complex numbers c = 3 + 4j d = complex(1, -2)
2. Basic Arithmetic Operations
Python supports all basic arithmetic operations for numerical data types. Here are some examples:
x = 5 y = 3 # Addition z = x + y # Output: 8 # Subtraction z = x - y # Output: 2 # Multiplication z = x * y # Output: 15 # Division z = x / y # Output: 1.6666666666666667 # Floor Division z = x // y # Output: 1 # Modulo z = x % y # Output: 2 # Exponentiation z = x ** y # Output: 125
3. Type Conversion
Python allows you to convert numerical data types from one to another. Here's an example:
x = 5 y = 3.14 # Convert x to a floating-point number and add it to y z = float(x) + y print(z) # Output: 8.14
In this example, we convert the integer "x" to a floating-point number using the float()
function and add it to the floating-point number "y".
4. Built-in Functions Python has several built-in functions for working with numbers. Here are some examples:
# Absolute value x = abs(-10) # Output: 10 # Round to a certain number of decimal places y = round(3.14159, 2) # Output: 3.14 # Maximum and minimum values z = max(1, 2, 3) # Output: 3 a = min(4, 5, 6) # Output: 4
5. Math Module
Python also has a math module that provides additional mathematical functions. Here's an example:
import math # Square root x = math.sqrt(25) # Output: 5.0 # Trigonometric functions y = math.sin(0) # Output: 0.0 z = math.cos(math.pi) # Output: -1.0
6. Floats
Floats are used to represent real numbers with decimal points. They are also known as floating-point numbers. In Python, float is represented by float
class. We can create a float variable by assigning a value with a decimal point to it.
Here's an example:
# Example of float x = 3.14 y = 2.5 print(x) print(y)
Output:
3.14 2.5
We can also use mathematical operations with floats:
# Example of float with mathematical operations x = 3.14 y = 2.5 z = x + y print(z)
Output:
5.64
Complex numbers are used to represent numbers with a real and imaginary part. In Python, complex numbers are represented by complex
class. We can create a complex number by specifying the real and imaginary parts separated by a +
or -
sign.
Here's an example:
# Example of complex number x = 2 + 3j y = 4 - 2j print(x) print(y)
Output:
(2+3j) (4-2j)
We can also use mathematical operations with complex numbers:
# Example of complex number with mathematical operations x = 2 + 3j y = 4 - 2j z = x + y print(z)
Output:
(6+1j)
We can convert one type of number into another using type conversion functions. Here are some type conversion functions in Python:
int(x)
converts x to an integer.float(x)
converts x to a floating-point number.complex(x)
converts x to a complex number with a zero imaginary part.complex(x, y)
converts x and y to a complex number with real part x and imaginary part y.Here are some examples:
# Example of type conversion x = 10 y = 3.14 z = 2 + 3j # convert x to float a = float(x) # convert y to int b = int(y) # convert z to float c = float(z) print(a) print(b) print(c)
Output:
10.0 3 (2+3j)
We have covered the basics of Python Numbers in this tutorial.
Test your C Programming skills with this comprehensive mock test on C Programming.
Take TestSolve most asked Interview Questions on Flutter and Test your foundational skills in flutter.
Take TestSolve most asked GATE Questions in Operating Systems and test your Gate Score.
Take TestThis is a mock test designed to help you assess your knowledge and skills in HTML and CSS.
Take TestSolve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.
Take Test