<jupyter_start><jupyter_text>Variable Types - NumbersIn the last class we saw how to assign values to variables using the = symbol. We also learnt what a valid variable name is. In this lesson we'll look at two of the different types of value which can be assigned to a variable; integers and floats. We'll also see how the different mathematical operators work.Python supports three different types of number; integer, float and complex. We won't concern ourselves with complex numbers in this course. IntegersAn integer is a whole number, without a decimal point. We can use the type() function to see what type a variable is:<jupyter_code>integer1 = 10

print(type(integer1))<jupyter_output><class 'int'><jupyter_text>FloatsA floating point number is a number with a decimal point:<jupyter_code>float1 = 0.5

print(type(float1))<jupyter_output><class 'float'><jupyter_text>You can convert integers to floats, and vice versa.Here, I'll convert an integer to a float using the int() function:<jupyter_code>integer2 = int(2.1)

print(integer2)<jupyter_output>2<jupyter_text>It looks like the int() function rounded down; what happens when the first decimal number is greater than 5?<jupyter_code>integer3 = int(2.9)

print(integer3)<jupyter_output>2<jupyter_text>So, we now know that the int() function chops off the decimal part of the number and doesn't round the part before the decimal.Let's convert an integer to a float and see what happens:<jupyter_code>float2 = float(5)

print(float2)<jupyter_output>5.0<jupyter_text>Using the float() function adds a decimal place to an integer. Addition, Subtraction, Division, Multiplication... and a couple moreWe can do maths really easily in Python. AdditionHere, I'm going to add two numbers together:<jupyter_code>subTotal = 5 + 5
print(subTotal)<jupyter_output>10<jupyter_text>I can also add a number to a variable:<jupyter_code>total = subTotal + 20
print(total)<jupyter_output>30<jupyter_text>SubtractionWe can subtract numbers:<jupyter_code>stockToday  = 100 - 20
print(stockToday)<jupyter_output>80<jupyter_text>And we can also subtract numbers from variables:<jupyter_code>salesToday = 40

stockTomorrow = stockToday - salesToday

print(stockTomorrow)<jupyter_output>40<jupyter_text>MultiplicationWe can do multiplication:<jupyter_code>avgLenOfWord = 9

avgLenOfSentence = 12

avgLettersInASentence =  avgLenOfWord * avgLenOfSentence

print(avgLettersInASentence)<jupyter_output>108<jupyter_text>DivisionAnd we can do division:(division always results in a floating point number)<jupyter_code>amountOfSpaghetti = 1000

numberOfPeople = 10

spaghettiPerPerson = amountOfSpaghetti / numberOfPeople

print(spaghettiPerPerson)<jupyter_output>100.0<jupyter_text>ModulusWe can also get the remainder of a number when it is divided by another number:<jupyter_code>remainder = 10 % 3

print(remainder)<jupyter_output>1<jupyter_text>ExponentsWe can raise a number by a power:<jupyter_code>startingRabbits = 2

numberOfDays = 3

finalRabbits = startingRabbits ** numberOfDays

print(finalRabbits)<jupyter_output>8<jupyter_text>Floor divisionWe can remove the decimal points when a division is not exact:<jupyter_code>print(11 / 3)
print(11 // 3)<jupyter_output>3
{'fraction_non_alphanumeric': 0.07231920199501247, 'fraction_numerical': 0.02275561097256858, 'mean_word_length': 6.826829268292683, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '83558', 'license': 'MIT', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1018, 'n_words': 333, 'path': 'PlotlyandPython/Lessons/(01) Intro to Python/Notebooks/(02) Variable Types - Numbers.ipynb', 'repo_name': 'peternewman22/Python_Courses', 'size': '3208'}