These exercises are about data types from Session 1 session1.

Exercise 1 - Functions

help(pow)
## Help on built-in function pow in module builtins:
## 
## pow(base, exp, mod=None)
##     Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments
## 
##     Some types, such as ints, are able to use a more efficient algorithm when
##     invoked using the three argument form.
pow(4,13.3)
## 101718016.92449336
myfloat = pow(4,13.3)
type(myfloat)
## <class 'float'>
myint = int(myfloat)
type(myint)
## <class 'int'>
mystr = int(myint)
mystr
## 101718016
type(mystr)
## <class 'int'>

Exercise 2 - Variables

myfirst_var = 1

print(myfirst_var)
## 1
operation_var = 2+2

print(operation_var)
## 4
1_var = 1

print(1_var)
##   File "<string>", line 1
##     1_var = 1
##      ^
## SyntaxError: invalid decimal literal
##   File "<string>", line 1
##     print(1_var)
##            ^
## SyntaxError: invalid decimal literal
var_1 = 1

print(var_1)
## 1
var_% = 1

print(var_%)
##   File "<string>", line 1
##     var_% = 1
##      ^
## SyntaxError: invalid decimal literal
##   File "<string>", line 1
##     print(var_%)
##                ^
## SyntaxError: invalid syntax

Exercise 3 - Coercion

coerce_var = "hello"

type(coerce_var)

int(coerce_var)
## <class 'str'>
## invalid literal for int() with base 10: 'hello'
bool(coerce_var)
## True
coerce_num = 3

str(coerce_num)
## '3'
coerce_var = "3"

type(coerce_var)
## <class 'str'>
int(coerce_var)
## 3
    
type(int(coerce_var))
## <class 'int'>

Exercise 4 - Concatenation

concatenated_str = "I" " code"

print(concatenated_str)
## I code
concatenated_str = "I" + " code"

print(concatenated_str)
## I code
concatenated_str = "I"
concatenated_str += " code"

print(concatenated_str)
## I code
concatenate_1 = "I"
concatenate_2 = " code"

print(concatenate_1 + concatenate_2)
## I code