Python Tutorial - 3. Numbers
Key Takeaways
This video tutorial covers the basics of numbers in Python, including simple mathematical operations, functions, and the order of operations. It demonstrates how to use Python as a calculator, perform arithmetic operations, and work with integers and floats.
Full Transcript
hello today's topic is numbers in Python numbers are very important in gradient of any program I cannot think of any software program in the world which doesn't use numbers so they're extremely important now in Python you can use Python programming language as a calculator so let me demonstrate that to you by doing some simple mathem iCal operations so for example you want to do addition of these two numbers you can do it like this so just type in two numbers and plus sign in between if you want to do subtraction you can do subtraction you can do division like this so for division you will use this SL shine if you want to do multiplication you will use star sign and it will multiply two numbers now if you want to find a remainder of uh a division then you will use a percentage sign so for example I want to divide 11 by 2 and I want to find out the remainder for that you will use percentage sign like this and you can guess what will be the answer okay I think you guessed it right so 11/ 2 is like 2 into 5 is 10 and then remainder will be one you can also find the power of any number so for example you want to find 3 to the power of two then the way you do that is by using two star sign 2 times so it will do this so 3 to ^ of 2 is 9 Guess What will be the answer of this this is 2 to the power of four 16 okay so when you are doing any number manipulation when you're writing any Python program uh normally you would create variables to store these numbers and you will do these mathematical operations on those variables okay so let me let me demonstrate this by having a simple problem so for example you want to travel from New York to Baltimore and then from Baltimore to Pittsburgh and you know the distance between these cities now you want to find out the total distance so the way you do it is you first create a variable to store the distance between New York City to Baltimore let's say it is 188 miles so I just created a variable called this and assign value 188 to it then you create another variable to store the distance between Baltimore to Pittsburgh and let's say this is 247 miles okay so to find out the total distance you create another variable called total distance and you just assign those first two variables to it so when I do like this and if I print the total distance it will tell me the total distance that I will be traveling during my journey okay another interesting problem could be let's say if you are driving at 65 miles per hour and you want to find the total time that you will spend in your journey and we're just assuming you're not taking any breaks you're like a super human being you don't need any brakes you can just constantly Drive okay so in that case again create another variable for your miles per hour speed so mph is equal to 65 this is your miles per hour and to find out the time you create another variable called time and say time equal to total distance if you have total distance and if you have miles per hour how do you find out the time right it's a simple math it is distance divided by the speed so distance divided by Miles hour is your time it's just a simple high school math or school math So when you say time it prints this number so you see um it's 6.69 hours now it is printing it with a lot higher decimal Precision you see after dot you see so many many decimal points if you want to see like just for Simplicity if you want to see like two decimal points you can use this round function so in Python there is this function called round where the first argument is as you see it in the tool tipe it's a number so your number is time and how many decimal points you want to see so you can say two so it is showing it as you see like after do you now see only two decimal points 1 two if you want to see like three decimal point Precision you can do this and it will show you three decimal points okay so just to summarize you can do all the basic mathematical operations in Python using these operator signs also there are two kind of numbers in Python one is integer which is like a whole number so for example 435 16 2 2 4 all these are integer numbers because they don't have a fractional part to it whereas this number is called a float number because it has a fractional part it's not a whole number basically it has a fraction to it so just remember this thing that two types of numbers integers and floats all right now let me show you something uh interesting so if I do let's say if I want to add 10 if I do this kind of operation uh just take a pause and uh think about what will be the answer what what will be the expected output okay all right so I'm just about to hit enter and you will see in a moment what it it prints now what were you expecting some of you might be expecting that it will do 10 + 2 which is 12 and then it will multiply it by 3 so 12 into 3 will be 36 but that's not what it printed why well the reason is the way python works is it has a priority on certain mathematical operations so for example in this case it will do 2 * 3 first so 2 * 3 is 6 and then it will add it to 10 so 10 + 6 is 16 if you want to do what you expected which is 10 + 2 and then multiply by 3 you need to use brackets so opening bracket 10 + 2 closing bracket cross 3 so by providing these brackets you are telling your programming platform form that I want the mathematical operation to happen in this order 10 + 2 and then three now you get 36 okay cool now let me show you one more interesting thing so 6 - 5.7 again take a pause and think what will be the answer it's really easy to Guess that right it should be 0.3 but let's see what happens oohoo why the hell I got this answer why is it not 0.3 well there is an answer so in any programming language when you try to store floating number It ultimately numbers are stored in binary format which is a sequence of 0o and one and the way protein numbers are stored they always lose the accuracy so there is no prec precise way to store floating numbers hence you will get this kind of behavior and this is not just with python this is with any programming languages and it's expected so it's not a bug or anything it is an expected output so if you want to again see3 then use rounding number round rounding function so just say around this particular number by two decimal points and you get 0.3 okay so that was all about numbers thanks for watching
Original Description
This python tutorial gives you an understanding of numbers. It will teach the use of numbers in python, perform simple mathematical operations, functions in python and order of operation.
Topics that are covered in this Python Video:
0:00 Introduction
4:49 round() function
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Video without background music: https://youtu.be/pd2_ZbhFT38
Visit http://codebasicshub.com/tutorial/python/numbers-1 to download answers on exercises.
Next Video:
Python Tutorial - 4. Strings: https://www.youtube.com/watch?v=PsoKq0p5meU&list=PLeo1K3hjS3usILfyvQlvUBokXkHPSve6S&index=5
Website: https://codebasics.io/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Playlist
Uploads from codebasics · codebasics · 3 of 60
1
2
▶
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
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
More on: Python for Data
View skill →Related Reads
🎓
Tutor Explanation
DeepCamp AI