top of page

# Variable Assignment

In this section, we'll talk about variables, data types, and assigning these variables in a meaningful way

## Data Types

There are many data types in Python. For this section, we'll be focusing on String, Integers, and Floats.

### String

Strings in Python are a Text type. They can be thought of as 'words'. They are always encompassed in double quotation marks.

Declaration: str = "hello"

Use: Print(str), Print("hello")

In this example, we declared the variable 'str' to take on the string value of "hello'. When we write

Print(str), this will print out the value of str ("hello") to the console. Similarly, 'Print("hello")' acts in the same way.

### Integer/Float

Integers and Float are Numeric Types in Python. Integers represent all positive and negative whole numbers (...,-3,-2,-1,0,1,2,3,...). Floats in Python can be thought of as decimals.

Declaration: int = 402, flo = 243.102

Use: Print(int), Print(flo), Print(402)

In this example, we declared the variable 'int' to take on the integer value of 402 When we write

Print(int), this will print out the value of int to the console. Similarly, we declared the variable 'flo' to take on the float value of 243.102. What happens when we do 'Print(flo)'?

### Methods

We can concatenate strings by using '+'. For example, we can take x = "hello" + " world". Then Print(x) will print "hello world". We can also do operations with numerical types. For example, Print(5*20.5) will print the actual numerical value, which is 102.5.

### Exercises:

1. Make an int variable which stores the value of 15*19. Print the variable.​

2. Print the concatenation of “hello” and “ goodbye”.

3. Initialize a variable to be the product of an int and float. Print this variable.

bottom of page