Variables and Assignments

-> Assignments and variables are fundamental ideas in computer programming. They give programmers the ability to manage, store, and alter data. In the realm of programming and computer science, knowing how to declare and assign values to variables is an essential ability.

Different types of Data (Data Type)

Data types are a kind of variable in which there are 3 main ones listed below:

-> Integer ⚫ Mathmatecal number -> Boolean ⚫ true or false ⚫ yes or no -> Text (aka string) ⚫ anything text stored variable

highScore = 100 #integer
isFriday = False  #boolean
favColor = "blue"  #text/string

print(str(highScore))
print(str(isFriday))
print(str(favColor))
100
False
blue

Popcorn Hack

Define an integer, a boolean, and a string and print all three of them together

bigNumber = 10000
isWednesday = True
firstName = "Arnav Nadar"

print(str(bigNumber) + "  "  + str(isWednesday) + "  " + str(firstName))
10000  True  Arnav Nadar

Changing/Replacing/Assigning variables

A variable will not change by it self so you will have to update the variable constantly. An example of this could be the variable of someone’s changing height.

currentScore = 100 

highScore = currentScore  # overe here we are assigning the value of currentscore to highScore, so right now bot strings have a value of 100

currentScore = 70  # Over here when you assign currentScore a new value that doesn't mean highScore changes. 

print(str(currentScore))

print(str(highScore))
70
100
# This ones a little harder!

num1 = 30
num2 = 100
num3 = 50
num2 = num3
num3 = num1
num1 = num2

print(str(num1))

print(str(num2))

print(str(num3))
50
50
30