Changes

Jump to navigation Jump to search

Workshop: Introduction to programming (with Python)

58 bytes added, 16:51, 21 September 2019
Types Of Variables
#Floats - Numbers w/ a decimal (ex: 1.0, 3.14, 7.77)
#Boolean - True or False
#Lists - An A sequential list of other variables (floats, integers, strings, more lists, or a mix) (ex: ['cat', 'dog', 999, 3.14, variable1])
===='''Defining Variables'''====
Answer: 1.5 + 3 = 4.5 but 4.5 is a float value. So for code #1 the answer is 4.5, but the "sum" variable in code #2 is an integer so the answer will be rounded down to 4.
It because of cases like these that sometimes we implement a technique known as casting. Casting simply means changing converting the type of information a variable holds. With casting we can turn a an int to a float, float to an int, str to an int, etc. We cast by writing the variable type we want ("float", "int", "str", etc.) followed by the variable/value we want to cast enclosed by parenthesis.
Examples:
*myList'''.insert('''x''')''' - Adds an element at the specified position (x)
*myList'''.clear()''' - Removes all the elements from the list
 
(We will discuss what methods are in a later section.)
<br />
118
edits

Navigation menu