<jupyter_start><jupyter_text>Python Variables  Variables Definition A Python variable is created the moment you first assign a value to it.<jupyter_code>n = 3      # int
x = 2.5    # float<jupyter_output><empty_output><jupyter_text>Variables do not need to be declared with any particular type. They get the type of their value.<jupyter_code>type(n)
type(x)<jupyter_output><empty_output><jupyter_text>Variables can change type after they have been set.<jupyter_code>n = 3.3
type(n)<jupyter_output><empty_output><jupyter_text>These are boolean and string variables:<jupyter_code>condition = False           # boolean
character_name = 'John'     # string<jupyter_output><empty_output><jupyter_text>Print the value of the variable:<jupyter_code>print(condition)
print(character_name)<jupyter_output>False
John<jupyter_text>Print the type of the variable:<jupyter_code>print(type(condition))
print(type(character_name))
n='No'   # n is now a string
print(type(n))<jupyter_output><class 'str'><jupyter_text>**variable name**: can only contain alpha-numeric characters and underscore (A-z, 0-9, and _)Variables names are case sensitive. Age and age are different variables.These are two different variables:<jupyter_code>age = 20
Age = 40
print('Laura is', age, 'years old. Her mother is', Age)<jupyter_output>Laura is 20 years old. Her mother is 40<jupyter_text>You can assign values to multiple variables in one line:<jupyter_code>name, age, grade = 'John', 20, 97.7
print('Name  =', name)
print('Age   =', age)
print('Grade =', grade)<jupyter_output>Name  = John
Age   = 20
Grade = 97.7<jupyter_text>Python Arithmetic Operators Operator | Name ---------|-----+ | addition- | subtraction* | multiplication/ | division% | modulus** | exponentiation We knew that:<jupyter_code>print('x =', x)
print('n =', n)
n = x   # Now n = 2.5<jupyter_output><empty_output><jupyter_text>By changing the value of the variable, you can change its type:<jupyter_code>print(n)
print(type(n))<jupyter_output><class 'float'><jupyter_text>We knew that:<jupyter_code>condition
not_condition = not condition
print(not_condition)<jupyter_output>True<jupyter_text>We knew that:<jupyter_code>character_name
full_name = character_name + ' Doe'
print(full_name)
m = 5
print(m/2)          #/ division
print(m//2)         #// floor division<jupyter_output>2<jupyter_text>Floor division only gets the integer part of the result.Floor division returns the quotient (answer or result of division) in which the digits after the decimal point are removed.<jupyter_code>print('5/3  =', 5/3)
print('5//3 =', 5//3)<jupyter_output>5/3  = 1.6666666666666667
5//3 = 1<jupyter_text>m % n: is the remainder of the floor division m//n<jupyter_code>m = 5
n = 3
print('Floor division: ', m, '//', n, '=', m//n)
print('Remainder:      ', m, ' %', n, '=', m%n)
print('Verification:   ', n,'*',m//n,'+',m%n,'=',n*(m//n)+(m%n))<jupyter_output>Floor division:  5 // 3 = 1
Remainder:       5  % 3 = 2
Verification:    3 * 1 + 2 = 5<jupyter_text>m**2 means x to the power of 2<jupyter_code>print('Square of ',m,':', m**2)
print('Square of ',n,':', n**2)<jupyter_output>Square of  5 : 25
Square of  3 : 9<jupyter_text>You can raise m to a higher power<jupyter_code>print(m, 'to the power of 2:', m**2)
print(m, 'to the power of 3:', m**3)
print(m, 'to the power of 4:', m**4)<jupyter_output>5 to the power of 2: 25
5 to the power of 3: 125
5 to the power of 4: 625<jupyter_text>It also works with negative values:<jupyter_code>print(m, 'to the power of -1:', m**-1)<jupyter_output>5 to the power of -1: 0.2<jupyter_text>Python Assignment Operators |  "Operator"  |  "Example"    |  "Same as"        || :-: | :- | :- || = | x = 5  |  x = 5 || += | x += 5 | x = x + 5 || -= | x -= 5 | x = x - 5 || *= | x *= 5 | x = x * 5 || /= | x /= 5 | x = x / 5 || %= | x %= 5 | x = x % 5 || //= | x //= 5 | x = x // 5 |<jupyter_code>m<jupyter_output><empty_output><jupyter_text>Adding 10<jupyter_code>m += 10
print(m)<jupyter_output>15<jupyter_text>Subtracting 2<jupyter_code>m -= 3
print(m)
type(m)<jupyter_output><empty_output><jupyter_text>Dividing by 4<jupyter_code>m /= 4
print(m)
type(m)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15156626506024096, 'fraction_numerical': 0.03180722891566265, 'mean_word_length': 4.862994350282486, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '21', 'dir': 'jupyter-structured-clean-dedup', 'id': '478613', 'license': 'MIT', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1561, 'n_words': 414, 'path': '02-Basic Python/01-Variables.ipynb', 'repo_name': 'Goliath-Research/Introduction-to-Data-Science', 'size': '4150'}