Python Programming Tutorial #2 - Basic Operators and Input

Tech With Tim · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

This video tutorial covers basic operators and input in Python programming, including addition, subtraction, division, and multiplication, as well as getting input from the console using the input function and working with variables and data types.

Full Transcript

hey guys so welcome to the second video in the series um if you remember in the last video we talked about data types and variables uh we went briefly into some of the things that python can do um today I'm going to be talking about operators and we're going to be doing some print statements some input um a little a few small console applications just applying some of the knowledge that we've learned so pretty much the first thing I want to do is I want to go back and I want to review what we did in the last lesson very quickly so we talked about variables and data types so for example the X variable we could set it to something equal to two like that uh a name we may equal to our name right so I make that equal to Tim um so there we go we have the name right there equal to Tim we'll start with that okay now if you remember in the last one I didn't talk about this but I used something called print now the print statement pretty much takes an argument so inside of these brackets the thing that is inside that brackets is called the argument so so it takes a uh a string argument usually so I will give it the name so now you'll see again we did this in the last one just want to review I'm clicking F5 simply to run the program when I go to the console it simply puts Tim onto the console just like that right okay um very basic we already did that so now let's say well we want to do something else so let's let's print here and we're just going to put a string and we're just going to type this in ourselves so let's say hello comma what is your name that's going to print to the console now we want to get what the user's name is now there's a way to do this in Python it's very simple we're going to make a variable name it makes sense to put the variable name here do an equal sign because it's a variable right and we're going to type the word input just like this now what's going to happen if I run the program here I'll show you is it's going to say hello what is your name and it's going to actually allow me now to type into the console which I couldn't do before now nothing happens after when I click enter because we don't have anything else after that but it's allowing me to type okay so now well we want to print out what the name is that was said so let's just simply type print and then name all right and we have hello what is your name I say oh well my name's Tim it says Tim all right now well we just printed out the name but maybe we want to go a little more advanced than that we want to say well hello Tim how are you doing Tim something like that right so I'm going to just put a comma here going to separate these two things and I'm going to put in a string and I'm just going to type it like the type so I'm going to say hello with a comma and then you see that I have this other comma here that is outside of the quotations meaning it's not a string it's actually just separating the two arguments in here and you'll notice what happens now what what I print is it goes hello what is your name so I say oh my name's Tim it says hello Tim right so that's pretty straightforward I hope that's easy to understand we're just using the input to get an input and then we're printing it back out to the screen okay so let's do um let's go into the next part of this now we'll use that again later but let's talk about operators so operator that term may sound familiar to you um in math uh we use things called operators so these four operators hopefully should look familiar to you um this is a plus sign this is the addition operator we have the minus sign which is the subtraction operator the division sign which is the well division operator and then the multiplication sign which is again the multiplication uh operator so there's a few more operators that we'll talk about but these are the four basic ones in Python now you remember how I talked to you about data types this is where this comes in when we use these operators it's important that we use them on certain data types so for example in math I could do something like 3 + 4 right so what is 3 + 4 equal well that is equal to 7 so the computer can actually do that math operation by using that operator to return those values so let's let's give an example here quickly so I have uh let's do num one we're going to use variables here uh remember I can use a number in the variable as long as it's not at the beginning and I'm going to give it a value of 45 and then we'll do num two and we're going to give it a value of three now if I want to print to the console um let's say num one plus num 2 well you can guess what that's going to give us it's going to give us 45 + three I hope if this is not error yeah so that gave us 48 right so oops didn't mean to make that full screen num one plus num 2 is 48 all right so now what about minus let's try this 42 basic um we can do multiplication here with the multiplication sign there we go 135 and then we'll try again with the division sign just to show you all of them we get 15.0 like that okay so that's pretty straightforward um those four basic operators now in Python there's a few more operators that we want to talk about now for example in math we have something called exponents right so how do we do exponents in Python well it's actually two stars is how you do an exponent all right and now maybe there's something called integer division um which I'll get into later but I'll just show you the operator for it right now it's two slashes that means uh I'll give you an example a math example here 64 divided by um let's do 10 um would give us usually in math a value of 6.4 right that's if you use one division sign sorry what am I doing times I mean divided by would give us 64 I have 6.4 but now if we do two division signs here like this it actually gives us a value of six that's because it just um it doesn't worry about the remainder at all it just tells us um how many times 10 can go into 64 um and that's all it can go in six times evenly so it gives us a whole number as our answer that's called integer division this double double slash like this okay and then we have another operator which is actually the modulus operator um so this is the percentage sign and this gives us the remainder so here if I do five modulus 2 then the remainder of that is actually 1 because 5 ID 2 is 4 then with a remainder of one right so it's not going to give us the decimal points it's again just going to give us the remainder if I did five ID four again the remainder is one 5id by three the remainder would be two like that okay so that's what the modulus sign um gives us so we'll put modulus here and then there's probably a few others that I'm forgetting about but we can go into those later so now um same thing let's keep using our number variables here and now let's introduce a third variable called num three now um I want to show you how we can use the variables so num one and let's see if you remember what this operator is uh so that's the exponent operator so that means num one which is going to be our base uh which is 45 raised to the power of four because we're going to use num two and we can print num three press okay and you can see we get a pretty large number um that's because of how exponents work and then same thing here if we want to do maybe integer division see what we're going to get we get 11 right a whole number and then say we want to do modulus we get one okay so now let's tie all of these things together with operators that we've used the variables the prints and the inputs so um let's start by just get doing a little print statement and saying pick a number okay pretty basic we're going to pick a number and then we're going to take the input so we're going to say num one again is equal to the input of that okay so we got the input in Num one um now let's say print pick another number all right so now we're going to pick another number so we're going to do num two is equal to input like that and now what we're going to do is we're going to introduce our third variable so we'll call it sum because we're going to add these is equal to num one plus num two and now actually you can't use sum because it's a reserve word so let's just do in all capitals some because remember how we talked about variables capitals and lowercase are different and then we're going to print to the console the sum like that okay so we run the program says pick a number uh let's pick a number let's say four and let's do 32 now what do you think it's going to be oh oops okay so yeah someone equal num one plus num two okay so this is why um I talked about data types so I'm actually uh Happy this happened it's because what actually happens when we get the input of something is it gives us the type of a string um which in this case is not what we wanted to do so um you saw there I'll run it again um it's a good mistake that this happened actually we have four and we have three and it gave us 43 that's just because we added the string 4 to the string three um so that simply gave us 43 but now we know in actual math that 4 + 3 equal 7 so if we want to do um the integers we have to actually convert these variables into integers so in order to do that remember I showed you the keyword um int like this before we're just going to put brackets around our two variables here like this integers and now hopefully we should get the correct answer when we do four and we do three and you can see we've got seven so um I didn't mean for that to happen originally but I'm happy it did because it shows us why data types are important so when we take the input of something we're typing it from the keyboard and that is actually a string so um here we can print again um don't worry about what I'm doing right now but I just want to show you the type which is going to give us if it's a string if it's an integer of num two just to show you what the type actually is so we pick a number we pick two and we pick three it tells us that three is actually a string so that's why when we added originally three and two or two and three or whatever it was um it gave us just them added together so two and three rather than what it should be which is five okay now same thing here if we had a number and we wanted to convert it into a string all we would do is we would type Str Str around the num so for example three and then that would give us three just like that so A String so now we've kind of gone over conversion of variables um conversion of numbers data types how to get input from the console using the input like this um and some basic operators of python so uh review this I hope you followed along and then in the next lesson we'll move into some more advanced operators and we'll maybe start with conditions okay I hope you enjoyed uh please subscribe like the video and I'll see you in the next video

Original Description

This is the second video in my python programming series. In this video I cover basic operators and talk about getting input from the console. Python is a great language to learn if you are just starting off coding and programming. It is easy to understand and gives you a great foundation for future learning. Text-Based Tutorial: https://techwithtim.net/tutorials/python-programming/beginner-python-tutorials/basic-operators-input/ Please LIKE and SUBSCRIBE! Python website: Video Tags: python,python tutorial,python language,python full course,python course,learn python,learn python programming,python tutorial for beginners,python tutorial 2018,python programming tutorial,python programming language,software development,programming tutorial,freecodecamp
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 3 of 60

1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

This video tutorial teaches basic operators and input in Python programming, covering topics such as variables, data types, and basic arithmetic operations. It provides a foundation for beginners in Python programming and helps them understand how to write simple programs and work with user input.

Key Takeaways
  1. Run the program to see the print statement in action
  2. Use the input function to get user input
  3. Print the user's input back to the screen
  4. Use operators to perform basic math operations
  5. Use variables in mathematical operations
  6. Print the result of a mathematical operation to the console
  7. Use the exponent operator (**)
  8. Use the integer division operator (//)
  9. Use the modulus operator (%)
💡 Understanding basic operators and input is crucial for writing effective Python programs, and working with variables and data types is essential for performing mathematical operations and getting user input.

Related Reads

📰
Corvorum OS 1.0 - Sistema Operativo Tecnomántico
Learn about Corvorum OS 1.0, a technomantic operating system with local AI and Windows support, and how it can benefit developers
Dev.to · Technomantus Corvi
📰
Why Materials Scientists Are Still Copy-Pasting Data from PDFs in 2026 (And Why AI Changes…
Materials scientists still copy-paste data from PDFs, but AI can change this tedious task
Medium · AI
📰
How to Actually Cap AI Spend for Your Users: 3 Edge Cases Everyone Misses
Learn to effectively cap AI spend for users by addressing 3 often-missed edge cases, ensuring cost control and preventing unexpected expenses.
Dev.to · CJ Cummings
📰
Nano Banana 2 Lite with Kiro
Learn to set up and configure Google Nano Banana 2 Lite with Kiro for MCP, a crucial skill for developers and engineers working with cutting-edge technology
Dev.to · xbill
Up next
How to Build Trusted Knowledge Platforms in the AI Era | Charles (Zapnito)
AI InterConnect
Watch →