Hey guys, today I will be covering data types and math
Few data types
- integers
- strings
- boolean
- lists
This is how you declare in int(integer)
num = 2 # this num variable stores a number
Strings
word = "Python" # this is how you declare a string (add quotes. Can be single or double)
Boolean
is_male = True # capitalize the T
lists
nums = [1, 2, 3, 4, 5] # a list can contain multiple values unlike a variable which can only contain one value
# a list can contain different data types, so you can do this
values = ["Python", 1, True, False, 2, "car"]
Math in Python
print(2 + 2) # this will output 4 to the console
You can use these to do basic math
- +
- -
- *
- /
- %
print(2 - 2) # outputs 0 to the console
print(2 * 2) # outputs 4 to the console
print(10 / 5) # outputs 2 to the console
print(2 % 2) # % (modulus) operator outputs the remainder, so in this case 0
First of all, why?
@CodeLongAndPros I am not sure what you mean!
@SUHASTADIPARTH1 You gave a tutorial on creating variables and doing math, and you call that complete?
@CodeLongAndPros No, I have a tutorial series. And this is the second tutorial in the series. I have more tutorials coming up.
@SUHASTADIPARTH1 but if it's a series then it would probably be called cycle squeezing
@SUHASTADIPARTH1 well, at least most people would, if it's a really long part 1 and a long part 2, i wouldn't call that cycle squeezing. but this is really short, i would really recommend to make it one long tutorial or 2 long tutorials.
@Kookiez sure, in the future though
@Bookie0 yes, I was just covering the basics. Not advanced stuff. But thanks for the feedback.
@SUHASTADIPARTH1 yea, but you can join all the "basic" tutorials together
@Bookie0 ok. I will do that next time.
There are also a
//
too, which do the same as/
but return a integer instead of float ( as my brain said ).@Wumi4 Yes, I know that. But I wanted to cover the basics, not advanced.
@SUHASTADIPARTH1 those are basics lol
@Bookie0 oh, i thought they were a bit advanced. I wanted cover the most basic operators.
@SUHASTADIPARTH1 almost every tutorial covers them
@Bookie0 well, ok. I will do that next time.
yay @SUHASTADIPARTH1
@SUHASTADIPARTH1 And modulo is basic? Anyways, you can emulate // by doing int(x /y) or int(str( x /y).split('.)[0)
@CodeLongAndPros That is true. I think I am going to make a tutorial on this. Using the advanced operators.